0

How to display image data type from sql to c# picture box?

27th Dec 2019, 3:29 PM
Miki Yas
2 Respuestas
+ 1
First you need to read the data from the database Then you need to store the result in a stream. And assign the stream to the picture box Below some quottes and links, where this is demonstrated. https://stackoverflow.com/questions/39527782/reading-sql-varbinary-blob-from-database/39599767 cmd.CommandText = "SELECT MyBlobColumn FROM MyTable WHERE Id = 1"; // note the usage of SequentialAccess to lower memory consumption (read the docs for more) using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { if (reader.Read()) { // again, we map the result to an SqlBytes instance var bytes = reader.GetSqlBytes(0); https://stackoverflow.com/questions/32326130/how-to-read-blob-from-sql-server/32326227 SqlCommand command = new SqlCommand(); SqlDataReader reader = command.ExecuteReader(); System.IO.Stream stream = reader.GetStream(1); // 1 is the index of the column https://stackoverflow.com/questions/9652634/c-sharp-reading-blob-from-sql-server-and-display-to-picture-box MemoryStream memoryStream = new MemoryStream(outbyte); pictureBox.Image = Image.FromStream(memoryStream); or https://www.codeproject.com/Questions/496613/Howplustoplusdisplayplusimageplusfromplusmsplussql MemoryStream stmBLOBData = new MemoryStream(byteBLOBData); pictureBox1.Image = Image.FromStream(stmBLOBData); Bitmap bmpImage = new Bitmap(ms); pictureBox1.Image = bmpImage ; Please use proper tags in your question, this helps attracted people that can help you to your question. Tags like c#, sql, image
27th Dec 2019, 9:44 PM
sneeze
sneeze - avatar
+ 1
Thank u bro, it really works
28th Dec 2019, 7:23 AM
Miki Yas