| | |
Reading binary data from SPROC..help please...
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
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 asp.net bitmap box broadcast c# check checkbox client combobox communication control conversion csharp database databaseconnection datagrid datagridview dataset datetime dbconnection decryption degrees design draganddrop drawing encryption enum eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net image input install java label libraries list loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql netcfsvcutil.exe numeric operator path photoshop php picturebox pixelinversion platform polynomial post programming properties radians regex remoting richtextbox server sleep socket sql statistics string stringformatting study sun system.servicemodel table tcpclientchannel teamsuite text textbox thread time timer update usb usercontrol validation visualstudio webbrowser winforms wpf wpfc# xml





