C# - Show image from dataGridView to pictureBox

  • Thread starter Thread starter Babis Mour
  • Start date Start date
B

Babis Mour

Guest
Hallo,


I have a dataGridView populated with data from an MS SQL database. The database contains images with varbinary(MAX) type. I have write the following code that can read the path of the image that is saved to hard disk when you double click in the dataGridView and show the image to a pictureBox.


private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.CurrentRow.Selected = true;
int cardNo = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["cardNoDataGridViewTextBoxColumn"].FormattedValue);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT ImageFull FROM SS1 WHERE CardNo = '" + cardNo + "'", con);
string img = cmd.ExecuteScalar().ToString();
pictureBox1.Image = Image.FromFile(img);
con.Close();
}




I want to double click in the dataGridView and reads the image direct from the database and show it to a pictureBox.

Could you please help me with this?

Continue reading...
 
Back
Top