Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the fourth position I have stored an Image and it is stored as "Binary data".

I want to view that "Binary data" stored in an SQL Database in a Gridview.

How do I do that?

No error codes the image column does not even display.
C#
string connStr2 = ConfigurationManager.ConnectionStrings["ImageMDFdb"].ConnectionString;
string cmdStr2 = "SELECT * FROM [ImageTable];";
byte[] btImage = null;
DataSet ds = new DataSet();
try
{
    using (SqlConnection conn2 = new SqlConnection(connStr2))
    {
        using (SqlCommand cmd2 = new SqlCommand(cmdStr2, conn2))
        {
            conn2.Open();
            using (SqlDataAdapter da = new SqlDataAdapter(cmd2))
            {
                da.Fill(ds);
                btImage = (byte[])ds.Tables[0].Rows[0][3];
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
            conn2.Close();
            cmd2.Dispose();
            conn2.Dispose();
        }
    }
}
catch (Exception ex)
{
    Label2.Text = "Gridview: " + ex.ToString();
}
Posted
Updated 23-Sep-14 6:00am
v4
Comments
PIEBALDconsult 23-Sep-14 12:02pm    
That would depend on the Gridview -- can it display images? If so, you'll need to populate an image from the data.

Check the below url

http://aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx

Hope the above url helps
 
Share this answer
 
v3
Hi
Better way is store the images in a folder and then save path of the image in table , so u can display images in the gridview

Thanks
 
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