Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just want to display the Image in my Image Control

This is my Database Tables
CREATE TABLE Logo(
 id int,
 image varbinary(max),
 status char(1)
) 


INSERT INTO Logo(id,status, image)
SELECT '1', 'Y', *
FROM OPENROWSET(BULK N'E:\logo.jpg', SINGLE_BLOB) image; 

select image from Logo where id=1 and status='Y'


aspx.cs
C#
protected void Page_Load(object sender, EventArgs e)
    {
        string constr = ConfigurationManager.ConnectionStrings["conn"].ToString();

        SqlConnection con = new SqlConnection(constr);
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "select image from Logo where id=1 and status='Y'";
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;

        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();
        
        Response.BinaryWrite((Byte[])dr[0]);
        con.Close();
        Response.End();
     }



Aspx Page
ASP.NET
<table >
<tr>
<td><asp:Image ID="logo" runat="server"/></td>
</tr>
</table >
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900