S
Seif Orabi
Guest
Hello,
I have a WinForm application that requires saving images to and retrieving them from an SQL Server database. To cut it short, nothing is wrong with the SQL statements embedded in C# code. When returning data using the SqlDataReader, all data is read except for the binary data in image columns. Heres my code:
rdr.Read();
if (rdr.HasRows && rdr[0].ToString() == txt_id.Text)
{
byte[] img = (byte[])rdr[4];
if (img != null)
{
MemoryStream ms = new MemoryStream(img);
pic1.Image = Image.FromStream(ms);
}
}
The img is always null and Im unable to convert the object at the specified column index to byte array. How can I read the image in order to display it in a picture box?
Thanks in advance
Continue reading...
I have a WinForm application that requires saving images to and retrieving them from an SQL Server database. To cut it short, nothing is wrong with the SQL statements embedded in C# code. When returning data using the SqlDataReader, all data is read except for the binary data in image columns. Heres my code:
rdr.Read();
if (rdr.HasRows && rdr[0].ToString() == txt_id.Text)
{
byte[] img = (byte[])rdr[4];
if (img != null)
{
MemoryStream ms = new MemoryStream(img);
pic1.Image = Image.FromStream(ms);
}
}
The img is always null and Im unable to convert the object at the specified column index to byte array. How can I read the image in order to display it in a picture box?
Thanks in advance
Continue reading...