| | |
Reading binary data from SPROC..help please...
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 6
Reputation:
Solved Threads: 0
Hi,
I'm trying to display an image that's stored in a SQL Server database. The ContentType and binary data are being returned but the image is coming up as a broken image. To test that the data is being retrieved I tried outputting the content type.
It is getting the corect data i.e. "image/pjpeg"
Then I tried Response.write for the binary data returned
It is outputting printing "System.Byte[]"
Am I right in saying the data is being returned from the SPROC?
Here is the code...
I'm trying to display an image that's stored in a SQL Server database. The ContentType and binary data are being returned but the image is coming up as a broken image. To test that the data is being retrieved I tried outputting the content type.
C# Syntax (Toggle Plain Text)
Response.Write(adm["Image_MIME_type"].ToString());
It is getting the corect data i.e. "image/pjpeg"
Then I tried Response.write for the binary data returned
C# Syntax (Toggle Plain Text)
Response.Write((byte[])adm["Image_image"]);
It is outputting printing "System.Byte[]"
Am I right in saying the data is being returned from the SPROC?
Here is the code...
C# Syntax (Toggle Plain Text)
if (adm.HasRows) { while (adm.Read()) { // Response.Write(adm["Image_MIME_type"].ToString()); Response.ContentType = adm["Image_MIME_type"].ToString(); Response.BinaryWrite((byte[])adm["Image_image"]); } } else { Response.Write("Reaer has no rows"); } adm.Close(); conn.Close();
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
Load the image into a byte array.
Pass the byte array into a memory stream
Pass the memory stream into a new or existing bitmap.
Error checking, null checking, etc needs to be added, left out for simplicity
Jerry
Pass the byte array into a memory stream
Pass the memory stream into a new or existing bitmap.
C# Syntax (Toggle Plain Text)
byte[] b = (byte[])adm["Image_image"]; System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true); stream.Write(b, 0, b.Length); Bitmap bmp = new Bitmap(stream);
Error checking, null checking, etc needs to be added, left out for simplicity
Jerry
Last edited by JerryShaw; Feb 26th, 2008 at 10:28 am.
![]() |
Other Threads in the C# Forum
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset datetime degrees development dll draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update upload usercontrol users validate validation visualstudio webbrowser wia windows winforms wpf xml





