Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Image data from Sql server to asp.net

Reply
Thread Tools

Image data from Sql server to asp.net

 
 
seeni
Guest
Posts: n/a
 
      12-01-2003
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


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      12-01-2003

"seeni" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Dave Rothgery
Guest
Posts: n/a
 
      12-01-2003

"Hans Kesting" <(E-Mail Removed)> wrote in message
news:OrIpNL$(E-Mail Removed)...
>
> "seeni" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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.




 
Reply With Quote
 
Bob Brunton
Guest
Posts: n/a
 
      12-24-2003
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" <(E-Mail Removed)> wrote in message news:<#(E-Mail Removed)>...
> "Hans Kesting" <(E-Mail Removed)> wrote in message
> news:OrIpNL$(E-Mail Removed)...
> >
> > "seeni" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving an image to SQL Server's image datatype Nathan Sokalski ASP .Net 9 08-03-2008 02:03 PM
Help. Getting a An error has occurred while establishing a connectionto the server. When connecting to SQL Server 2005, this failure may be causedby the fact that under the default settings SQL Server does not allow remote aboutjav.com@gmail.com ASP .Net 0 05-03-2008 12:43 PM
how to read image from sql server to show in a image =?Utf-8?B?am9l?= ASP .Net 2 07-24-2006 01:33 PM
Do the Self-Paced Training Kits: Microsoft SQL Server 2000 include Eval copy of SQL Server? Brian Whiting Microsoft Certification 2 12-29-2005 04:24 AM
Tools to extract data from SQL database and convert it into XML & insert XML data into SQL databases Harry Zoroc XML 1 07-12-2004 10:10 PM



Advertisments