title: how to load an image from datagridview on mouse click into picturebox in vb.net
body: <p>I am working on a project where I have a list of images displayed through datagridview.
  I want to load an image into picturebox when the particular image is clicked in datagridview.</p>
  
  <p>My code</p>
  
  <pre><code>Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
          sql.Open()
  
          cmd = New SqlCommand("select pic from detail4 where id='" &amp; DataGridView1.CurrentRow.Cells(0).Value() &amp; "'", sql)
          Dim imageData As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
          If Not imageData Is Nothing Then
              Using ms As New MemoryStream(imageData, 0, imageData.Length)
                  ms.Write(imageData, 0, imageData.Length)
                  PictureBox1.BackgroundImage = Image.FromStream(ms, True)
              End Using
          End If
  
      End Sub
  </code></pre>
  
  <p>I get Out of memory exception..
  What may be the problem.
  pls help</p>