Retreving images from sql to datagrid View windows Forms
Hi i have two colums in table, id and image i have stored my images in the Table ImgTB but the problem is while retreving the images. I just get a red cross.It would be great if some one can help me out
hears my code(a lot confused:))
private void disbtn_Click(object sender, EventArgs e)
{
SqlDataAdapter adpat = new SqlDataAdapter();
adpat.SelectCommand = new SqlCommand("select * from ImgTB", con);
con.Open();
DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
imageColumn.Name = "Picture";
imageColumn.HeaderText = "picture";
imageColumn.ImageLayout = DataGridViewImageCellLayout.Zoom;
try
{
imageColumn.Image = byteArrayToImage((byte[])dt.Tables["ImgTB"].Rows[1]["picture"]);
}
catch(Exception ex)
{
MessageBox.Show(e.ToString());
}
dataGridView1.Columns.Insert(0, imageColumn);
adpat.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
private Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}