S
seeni
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=NorthWind");
// 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
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=NorthWind");
// 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