Then, refer to the following code to display the image:
// create sql connection, sql command..
//sql statement: select ImageID, Image from ImageTable.
var da = new SqlDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds, "Images");
int count = ds.Tables["Images"].Rows.Count;
if (count > 0)
{ //get the image byte.
var data = (Byte[])(ds.Tables["Images"].Rows[count - 1]["Image"]);
var stream = new MemoryStream(data);
pictureBox1.Image= Image.FromStream(sream);
//you could use the following code to get the image id var ImageID = (ds.Tables["Images"].Rows[count - 1]["ImageID"]).ToString();
}
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
All-Star
45489 Points
7008 Posts
Microsoft
Re: Retrieving varbinary field from sql query with other fields to picturebox in a windows form
Jun 02, 2017 03:18 AM|Zhi Lv - MSFT|LINK
Hi Jose,
Yes, you can do it. You could use the SqlDataReader or SqlDataAdapter method to execute the SQL command statement, and get the result.
More details about suing these method, see:
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader(v=vs.110).aspx
Then, refer to the following code to display the image:
Best regards,
Dillion