473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Image data from Sql server to asp.net

I have tried retrieving the image data from NorthWind database and print in
the asp page using Repeater control. But instead of showing picture, the
browser is showing "System.Byte[]"

My code is
In codebehind file.

private void Page_Load(object sender, System.EventArgs e)
{

if(!Page.IsPostBack)

{

SqlConnection myConnection = new
SqlConnection("server=test2;uid=sa;pwd=;database=N orthWind");

// Connect to the SQL database using a SQL SELECT query to get

// all the data from the "Titles" table.

SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM" +

" Categories", myConnection);

// Create and fill a DataSet.

DataSet ds = new DataSet();

myCommand.Fill(ds);
Repeater1.DataSource = ds;

Repeater1.DataBind();

}

}

In aspx file

<asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<font color="#cc3333" face="verdana" size="3"><b>DataList Control
Header</b> </font>
</HeaderTemplate>
<AlternatingItemTemplate>
<font face="verdana" size="2" color="green">
<br>
<b>Category ID: </b>
<%# DataBinder.Eval(Container.DataItem, "CategoryID") %>
<br>
<b>Category Name: </b>
<%# DataBinder.Eval(Container.DataItem, "CategoryName")%>
<br>
<b>Description: </b>
<%# DataBinder.Eval(Container.DataItem, "Description") %>
<br>
<b>Picture: </b>
<%# DataBinder.Eval(Container.DataItem, "Picture") %>
<p>
</div> </font>
</AlternatingItemTemplate>
<ItemTemplate>
<font face="verdana" size="2">
<br>
<b>Category ID: </b>
<%# DataBinder.Eval(Container.DataItem, "CategoryID") %>
<br>
<b>Category Name: </b>
<%# DataBinder.Eval(Container.DataItem, "CategoryName")%>
<br>
<b>Description: </b>
<%# DataBinder.Eval(Container.DataItem, "Description") %>
<br>
<b>Picture: </b>
<%# DataBinder.Eval(Container.DataItem, "Picture") %>
<p>
</div> </font>
</ItemTemplate>
<FooterTemplate>
<font color="#996600" face="verdana" size="1">DataList Control footer
</font>
</FooterTemplate>
</asp:repeater>

The output is

Category ID: 3
Category Name: Confections
Description: Desserts, candies, and sweet breads
Picture: System.Byte[]
Category ID: 4
Category Name: Dairy Products
Description: Milk and stuff
Picture: System.Byte[]
Category ID: 5
Category Name: Grains/Cereals
Description: Breads, crackers, pasta, and cereal
Picture: System.Byte[]
Category ID: 6
Category Name: Meat/Poultry
Description: Prepared meats
Picture: System.Byte[]
Category ID: 7
Category Name: Produce
Description: Dried fruit and bean curd
Picture: System.Byte[]
Thanks,
-Seeni
Nov 18 '05 #1
3 3751

"seeni" <m_***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I have tried retrieving the image data from NorthWind database and print in the asp page using Repeater control. But instead of showing picture, the
browser is showing "System.Byte[]"


You can't send image data along with the html code. Image data is retrieved
by the
browser in a separate request when it encounters an <img> tag.

What you need to do is this:
* generate an <img src=...> tag, with a URL that points to a special aspx
file (with some parameters)
* in that aspx, read the image from the database (based on the parameters)
* set an appropriate ContentType ("image/gif", "image/jpeg") and use
Response.BinaryWrite
to write the data.

Hans Kesting
Nov 18 '05 #2

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...

"seeni" <m_***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I have tried retrieving the image data from NorthWind database and print in
the asp page using Repeater control. But instead of showing picture, the
browser is showing "System.Byte[]"


You can't send image data along with the html code. Image data is

retrieved by the
browser in a separate request when it encounters an <img> tag.

What you need to do is this:
* generate an <img src=...> tag, with a URL that points to a special aspx
file (with some parameters)
* in that aspx, read the image from the database (based on the parameters)
* set an appropriate ContentType ("image/gif", "image/jpeg") and use
Response.BinaryWrite
to write the data.


Just as an FYI, according to the demos and previews I've seen, there will be
a "DynamicImage" control in the next version of ASP.NET which can be bound
to a binary column in a database. Not all that useful for now, but it's
something to think about in the long run.


Nov 18 '05 #3
Well if microsoft put out a Dynamic Image control they are wasting
their time because it already exists.

I have used this control for 6 months now and I don't know anything
about HTTP Handlers or sending stuff other than HTML down the HTTP
response.

Go to the Microsoft ASP.NET Control Gallery.

http://www.asp.net/ControlGallery/Co...773&tabindex=2

Regards Bob
"Dave Rothgery" <dr*******@alum.wpi.edu> wrote in message news:<#0**************@tk2msftngp13.phx.gbl>...
"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...

"seeni" <m_***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I have tried retrieving the image data from NorthWind database and print in the asp page using Repeater control. But instead of showing picture, the
browser is showing "System.Byte[]"


You can't send image data along with the html code. Image data is

retrieved
by the
browser in a separate request when it encounters an <img> tag.

What you need to do is this:
* generate an <img src=...> tag, with a URL that points to a special aspx
file (with some parameters)
* in that aspx, read the image from the database (based on the parameters)
* set an appropriate ContentType ("image/gif", "image/jpeg") and use
Response.BinaryWrite
to write the data.


Just as an FYI, according to the demos and previews I've seen, there will be
a "DynamicImage" control in the next version of ASP.NET which can be bound
to a binary column in a database. Not all that useful for now, but it's
something to think about in the long run.

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
3
by: Christopher Mouton | last post by:
We regularly make drive images of our entire server and store it at a backup site. To be honest I have never fully understood how the imaging programs deal with open files. My question is will the...
1
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks-...
2
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image....
35
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
4
by: serge | last post by:
I was working on figuring out where a certain application was storing the multiple selection choices I was doing through the app. I finally figured out that they were being store in an IMAGE data...
4
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the...
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
1
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.