how to display multiple images from sql server to multiple picturebox at runtimeHow do you get a string from a MemoryStream?Problem in saving image to database from picturebox. VB.Net 2008. Framework 3.5Installing .NET application with databaseHow to connect database in vb.net(Database is installed in mixed mode)Display an image in picturebox from specific positionDisplay an image from datagridview to a pictureboxHow can I populate a listbox with data from an mdb database in Visual Basic 2012?Displaying images from a picturebox listHow to edit and delete data in DataGridView?Convert listbox to DataGridView

Find the area of the rectangle

Single word that parallels "Recent" when discussing the near future

Why does Taylor’s series “work”?

Why is Drogon so much better in battle than Rhaegal and Viserion?

When the match time is called, does the current turn end immediately?

Why is so much ransomware breakable?

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

Would a "ring language" be possible?

Gimp perspective tool is not actually transforming

Do we see some Unsullied doing this in S08E05?

What kind of environment would favor hermaphroditism in a sentient species over regular, old sexes?

AD: OU for system administrator accounts

Is Precocious Apprentice enough for Mystic Theurge?

Why use a retrograde orbit?

How to handle professionally if colleagues has referred his relative and asking to take easy while taking interview

Can EU citizens work in Iceland?

Why do academics prefer Mac/Linux?

Polynomial division: Is this trick obvious?

How to deal with the extreme reverberation in big cathedrals when playing the pipe organs?

Why didn't Daenerys' advisers suggest assassinating Cersei?

How was the blinking terminal cursor invented?

Cannot remove door knob -- totally inaccessible!

Why doesn't Iron Man's action affect this person in Endgame?

Solenoid fastest possible release - for how long should reversed polarity be applied?



how to display multiple images from sql server to multiple picturebox at runtime


How do you get a string from a MemoryStream?Problem in saving image to database from picturebox. VB.Net 2008. Framework 3.5Installing .NET application with databaseHow to connect database in vb.net(Database is installed in mixed mode)Display an image in picturebox from specific positionDisplay an image from datagridview to a pictureboxHow can I populate a listbox with data from an mdb database in Visual Basic 2012?Displaying images from a picturebox listHow to edit and delete data in DataGridView?Convert listbox to DataGridView






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to display the picture result from my database inside the picture box on my form but I just don't know how to go about it. this is the code I have, please what change can I make to this code to achieve this.. thanks in advance



Dim cn As SqlConnection

cn = New SqlConnection
cn.ConnectionString = "Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"

Dim cmd As New System.Data.SqlClient.SqlCommand("use [E-commerce];SELECT ProductTB.ProductImage FROM ProductTB WHERE ProductID = 'shoe1'")
cn.Open()
cmd.Connection = cn

Dim ImgStream As New IO.MemoryStream(CType(cmd.ExecuteScalar, Byte()))
cmd.CommandType = CommandType.Text

ProductImagePictureBox.Image = Image.FromStream(ImgStream)

ImgStream.Dispose()

cmd.Connection.Close()


my question is how can i update this code to be able to display multiple images into my picture box










share|improve this question






























    0















    I am trying to display the picture result from my database inside the picture box on my form but I just don't know how to go about it. this is the code I have, please what change can I make to this code to achieve this.. thanks in advance



    Dim cn As SqlConnection

    cn = New SqlConnection
    cn.ConnectionString = "Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"

    Dim cmd As New System.Data.SqlClient.SqlCommand("use [E-commerce];SELECT ProductTB.ProductImage FROM ProductTB WHERE ProductID = 'shoe1'")
    cn.Open()
    cmd.Connection = cn

    Dim ImgStream As New IO.MemoryStream(CType(cmd.ExecuteScalar, Byte()))
    cmd.CommandType = CommandType.Text

    ProductImagePictureBox.Image = Image.FromStream(ImgStream)

    ImgStream.Dispose()

    cmd.Connection.Close()


    my question is how can i update this code to be able to display multiple images into my picture box










    share|improve this question


























      0












      0








      0


      1






      I am trying to display the picture result from my database inside the picture box on my form but I just don't know how to go about it. this is the code I have, please what change can I make to this code to achieve this.. thanks in advance



      Dim cn As SqlConnection

      cn = New SqlConnection
      cn.ConnectionString = "Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"

      Dim cmd As New System.Data.SqlClient.SqlCommand("use [E-commerce];SELECT ProductTB.ProductImage FROM ProductTB WHERE ProductID = 'shoe1'")
      cn.Open()
      cmd.Connection = cn

      Dim ImgStream As New IO.MemoryStream(CType(cmd.ExecuteScalar, Byte()))
      cmd.CommandType = CommandType.Text

      ProductImagePictureBox.Image = Image.FromStream(ImgStream)

      ImgStream.Dispose()

      cmd.Connection.Close()


      my question is how can i update this code to be able to display multiple images into my picture box










      share|improve this question
















      I am trying to display the picture result from my database inside the picture box on my form but I just don't know how to go about it. this is the code I have, please what change can I make to this code to achieve this.. thanks in advance



      Dim cn As SqlConnection

      cn = New SqlConnection
      cn.ConnectionString = "Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"

      Dim cmd As New System.Data.SqlClient.SqlCommand("use [E-commerce];SELECT ProductTB.ProductImage FROM ProductTB WHERE ProductID = 'shoe1'")
      cn.Open()
      cmd.Connection = cn

      Dim ImgStream As New IO.MemoryStream(CType(cmd.ExecuteScalar, Byte()))
      cmd.CommandType = CommandType.Text

      ProductImagePictureBox.Image = Image.FromStream(ImgStream)

      ImgStream.Dispose()

      cmd.Connection.Close()


      my question is how can i update this code to be able to display multiple images into my picture box







      vb.net






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 17:46







      lookatyouman

















      asked Mar 23 at 16:16









      lookatyoumanlookatyouman

      32




      32






















          1 Answer
          1






          active

          oldest

          votes


















          0














          As I suggested elsewhere:



          'Clear any existing images if required.
          For Each pictureBox In FlowLayoutPanel1.Controls.Cast(Of PictureBox)().ToArray()
          pictureBox.Image.Dispose()
          pictureBox.Dispose()
          Next

          Using connection As New SqlConnection("Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"),
          command As New SqlCommand("SELECT ProductImage FROM ProductTB", connection)
          connection.Open()

          Using reader = command.ExecuteReader()
          Do While reader.Read()
          Using stream As New MemoryStream(DirectCast(reader("ProductImage"), Byte()))
          Dim img = Image.FromStream(stream)
          Dim pictureBox As New PictureBox With .SizeMode = PictureBoxSizeMode.AutoSize,
          .Image = img

          FlowLayoutPanel1.Controls.Add(pictureBox)
          End Using
          Loop
          End Using
          End Using


          That assumes that you have added a FlowLayoutPanel control to your form named FlowLayoutPanel1. That control will allow you to add and remove controls at run-time and it will handle the layout automatically.



          The code above also cleans up some of the things you were already doing, like removing unnecessary parts from your SQL code and adding Using statements. It removes your WHERE clause and thus gets every record in the table. You can change that to just get some records if you want. The data reader will read each one in turn and add it to the form in a new PictureBox.






          share|improve this answer























          • Thanks man, the code works but only one image is been display on the flow layout, how can I go about that

            – lookatyouman
            Mar 24 at 1:17











          • If the FlowLayoutPanel only shows one PictureBox then only one PictureBox is being added, which means that only one record is being read. Before posting anything here, you need to debug your code. That means setting a breakpoint and stepping through the code line by line to see what it does. If you do that and you see only a single record being read then asking why only a single PictureBox is displayed would be a silly question. You know there's only one record and, if that's not what you expect, you need to then work out why that is. Most likely, there's only one record to read.

            – jmcilhinney
            Mar 24 at 1:41











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315781%2fhow-to-display-multiple-images-from-sql-server-to-multiple-picturebox-at-runtime%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          As I suggested elsewhere:



          'Clear any existing images if required.
          For Each pictureBox In FlowLayoutPanel1.Controls.Cast(Of PictureBox)().ToArray()
          pictureBox.Image.Dispose()
          pictureBox.Dispose()
          Next

          Using connection As New SqlConnection("Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"),
          command As New SqlCommand("SELECT ProductImage FROM ProductTB", connection)
          connection.Open()

          Using reader = command.ExecuteReader()
          Do While reader.Read()
          Using stream As New MemoryStream(DirectCast(reader("ProductImage"), Byte()))
          Dim img = Image.FromStream(stream)
          Dim pictureBox As New PictureBox With .SizeMode = PictureBoxSizeMode.AutoSize,
          .Image = img

          FlowLayoutPanel1.Controls.Add(pictureBox)
          End Using
          Loop
          End Using
          End Using


          That assumes that you have added a FlowLayoutPanel control to your form named FlowLayoutPanel1. That control will allow you to add and remove controls at run-time and it will handle the layout automatically.



          The code above also cleans up some of the things you were already doing, like removing unnecessary parts from your SQL code and adding Using statements. It removes your WHERE clause and thus gets every record in the table. You can change that to just get some records if you want. The data reader will read each one in turn and add it to the form in a new PictureBox.






          share|improve this answer























          • Thanks man, the code works but only one image is been display on the flow layout, how can I go about that

            – lookatyouman
            Mar 24 at 1:17











          • If the FlowLayoutPanel only shows one PictureBox then only one PictureBox is being added, which means that only one record is being read. Before posting anything here, you need to debug your code. That means setting a breakpoint and stepping through the code line by line to see what it does. If you do that and you see only a single record being read then asking why only a single PictureBox is displayed would be a silly question. You know there's only one record and, if that's not what you expect, you need to then work out why that is. Most likely, there's only one record to read.

            – jmcilhinney
            Mar 24 at 1:41















          0














          As I suggested elsewhere:



          'Clear any existing images if required.
          For Each pictureBox In FlowLayoutPanel1.Controls.Cast(Of PictureBox)().ToArray()
          pictureBox.Image.Dispose()
          pictureBox.Dispose()
          Next

          Using connection As New SqlConnection("Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"),
          command As New SqlCommand("SELECT ProductImage FROM ProductTB", connection)
          connection.Open()

          Using reader = command.ExecuteReader()
          Do While reader.Read()
          Using stream As New MemoryStream(DirectCast(reader("ProductImage"), Byte()))
          Dim img = Image.FromStream(stream)
          Dim pictureBox As New PictureBox With .SizeMode = PictureBoxSizeMode.AutoSize,
          .Image = img

          FlowLayoutPanel1.Controls.Add(pictureBox)
          End Using
          Loop
          End Using
          End Using


          That assumes that you have added a FlowLayoutPanel control to your form named FlowLayoutPanel1. That control will allow you to add and remove controls at run-time and it will handle the layout automatically.



          The code above also cleans up some of the things you were already doing, like removing unnecessary parts from your SQL code and adding Using statements. It removes your WHERE clause and thus gets every record in the table. You can change that to just get some records if you want. The data reader will read each one in turn and add it to the form in a new PictureBox.






          share|improve this answer























          • Thanks man, the code works but only one image is been display on the flow layout, how can I go about that

            – lookatyouman
            Mar 24 at 1:17











          • If the FlowLayoutPanel only shows one PictureBox then only one PictureBox is being added, which means that only one record is being read. Before posting anything here, you need to debug your code. That means setting a breakpoint and stepping through the code line by line to see what it does. If you do that and you see only a single record being read then asking why only a single PictureBox is displayed would be a silly question. You know there's only one record and, if that's not what you expect, you need to then work out why that is. Most likely, there's only one record to read.

            – jmcilhinney
            Mar 24 at 1:41













          0












          0








          0







          As I suggested elsewhere:



          'Clear any existing images if required.
          For Each pictureBox In FlowLayoutPanel1.Controls.Cast(Of PictureBox)().ToArray()
          pictureBox.Image.Dispose()
          pictureBox.Dispose()
          Next

          Using connection As New SqlConnection("Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"),
          command As New SqlCommand("SELECT ProductImage FROM ProductTB", connection)
          connection.Open()

          Using reader = command.ExecuteReader()
          Do While reader.Read()
          Using stream As New MemoryStream(DirectCast(reader("ProductImage"), Byte()))
          Dim img = Image.FromStream(stream)
          Dim pictureBox As New PictureBox With .SizeMode = PictureBoxSizeMode.AutoSize,
          .Image = img

          FlowLayoutPanel1.Controls.Add(pictureBox)
          End Using
          Loop
          End Using
          End Using


          That assumes that you have added a FlowLayoutPanel control to your form named FlowLayoutPanel1. That control will allow you to add and remove controls at run-time and it will handle the layout automatically.



          The code above also cleans up some of the things you were already doing, like removing unnecessary parts from your SQL code and adding Using statements. It removes your WHERE clause and thus gets every record in the table. You can change that to just get some records if you want. The data reader will read each one in turn and add it to the form in a new PictureBox.






          share|improve this answer













          As I suggested elsewhere:



          'Clear any existing images if required.
          For Each pictureBox In FlowLayoutPanel1.Controls.Cast(Of PictureBox)().ToArray()
          pictureBox.Image.Dispose()
          pictureBox.Dispose()
          Next

          Using connection As New SqlConnection("Data Source=ALLAYESQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True"),
          command As New SqlCommand("SELECT ProductImage FROM ProductTB", connection)
          connection.Open()

          Using reader = command.ExecuteReader()
          Do While reader.Read()
          Using stream As New MemoryStream(DirectCast(reader("ProductImage"), Byte()))
          Dim img = Image.FromStream(stream)
          Dim pictureBox As New PictureBox With .SizeMode = PictureBoxSizeMode.AutoSize,
          .Image = img

          FlowLayoutPanel1.Controls.Add(pictureBox)
          End Using
          Loop
          End Using
          End Using


          That assumes that you have added a FlowLayoutPanel control to your form named FlowLayoutPanel1. That control will allow you to add and remove controls at run-time and it will handle the layout automatically.



          The code above also cleans up some of the things you were already doing, like removing unnecessary parts from your SQL code and adding Using statements. It removes your WHERE clause and thus gets every record in the table. You can change that to just get some records if you want. The data reader will read each one in turn and add it to the form in a new PictureBox.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 0:34









          jmcilhinneyjmcilhinney

          26.8k32033




          26.8k32033












          • Thanks man, the code works but only one image is been display on the flow layout, how can I go about that

            – lookatyouman
            Mar 24 at 1:17











          • If the FlowLayoutPanel only shows one PictureBox then only one PictureBox is being added, which means that only one record is being read. Before posting anything here, you need to debug your code. That means setting a breakpoint and stepping through the code line by line to see what it does. If you do that and you see only a single record being read then asking why only a single PictureBox is displayed would be a silly question. You know there's only one record and, if that's not what you expect, you need to then work out why that is. Most likely, there's only one record to read.

            – jmcilhinney
            Mar 24 at 1:41

















          • Thanks man, the code works but only one image is been display on the flow layout, how can I go about that

            – lookatyouman
            Mar 24 at 1:17











          • If the FlowLayoutPanel only shows one PictureBox then only one PictureBox is being added, which means that only one record is being read. Before posting anything here, you need to debug your code. That means setting a breakpoint and stepping through the code line by line to see what it does. If you do that and you see only a single record being read then asking why only a single PictureBox is displayed would be a silly question. You know there's only one record and, if that's not what you expect, you need to then work out why that is. Most likely, there's only one record to read.

            – jmcilhinney
            Mar 24 at 1:41
















          Thanks man, the code works but only one image is been display on the flow layout, how can I go about that

          – lookatyouman
          Mar 24 at 1:17





          Thanks man, the code works but only one image is been display on the flow layout, how can I go about that

          – lookatyouman
          Mar 24 at 1:17













          If the FlowLayoutPanel only shows one PictureBox then only one PictureBox is being added, which means that only one record is being read. Before posting anything here, you need to debug your code. That means setting a breakpoint and stepping through the code line by line to see what it does. If you do that and you see only a single record being read then asking why only a single PictureBox is displayed would be a silly question. You know there's only one record and, if that's not what you expect, you need to then work out why that is. Most likely, there's only one record to read.

          – jmcilhinney
          Mar 24 at 1:41





          If the FlowLayoutPanel only shows one PictureBox then only one PictureBox is being added, which means that only one record is being read. Before posting anything here, you need to debug your code. That means setting a breakpoint and stepping through the code line by line to see what it does. If you do that and you see only a single record being read then asking why only a single PictureBox is displayed would be a silly question. You know there's only one record and, if that's not what you expect, you need to then work out why that is. Most likely, there's only one record to read.

          – jmcilhinney
          Mar 24 at 1:41



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315781%2fhow-to-display-multiple-images-from-sql-server-to-multiple-picturebox-at-runtime%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript