title: Show the picture from database to each usercontrol's picturebox?
body: <p>Usercontrol Code:</p>
  
  <pre><code>    private string lastName;
      public string LastName
      {
          get { return lastName; }
          set
          {
              lastName = value;
              textBox1.Text = value;
          }
      }
  </code></pre>
  
  <p>Form Code:</p>
  
  <pre><code>        using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
          {
              myDatabaseConnection.Open();
              using (SqlCommand SqlCommand = new SqlCommand("Select LastName, Image from Employee", myDatabaseConnection))
  
              {
  
  
  
                  int i = 0;
                  SqlDataReader DR1 = SqlCommand.ExecuteReader();
                  while (DR1.Read())
                  {
                      i++;
                      UserControl2 usercontrol = new UserControl2();
                      usercontrol.Tag = i;
                      usercontrol.LastName = (string)DR1["LastName"];
                      flowLayoutPanel1.Controls.Add(usercontrol);
                  }
  
  
              }
          }
  </code></pre>
  
  <p>With the code above i can show each LastName from database in each usercontrol's textbox. How to show the picture from database to each usercontrol's picturebox?</p>
  
  <p>This is how I display a single image from database:</p>
  
  <pre><code>        using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
          {
              myDatabaseConnection.Open();
              using (SqlCommand SqlCommand = new SqlCommand("Select LastName, Image from Employee where ID = @a", myDatabaseConnection))
              {
                  SqlCommand.Parameters.AddWithValue("@a", textBox1.Text);
                  DataSet DS = new DataSet();
                  SqlDataAdapter da = new SqlDataAdapter(SqlCommand);
                  da.Fill(DS, "Images");
                  var imagesTable = DS.Tables["Images"];
                  var imagesRows = imagesTable.Rows;
                  var count = imagesRows.Count;
  
                  if (count &lt;= 0)
                      return;
                  var imageColumnValue =
                      imagesRows[count - 1]["Image"];
                  if (imageColumnValue == DBNull.Value)
                      return;
  
                  var data = (Byte[])imageColumnValue;
                  using (var stream = new MemoryStream(data))
                  {
                      pictureBox1.Image = Image.FromStream(stream);
                  }
  
              }
          }  
  </code></pre>