Click here to Skip to main content
15,911,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i save the image in database in binary form how i retrieve display it form database in gridview

THIS IS MY TABLE

UserId  int
ImageName image


mycode is


 if (FileUpload1.HasFile)
        {
            byte[] ImageName = FileUpload1.FileBytes;
            string query = "Insert into Pictures(UserId,ImageName)values('" + Session["Id"].ToString() + "',@imagename)";
            SqlConnection conn = new SqlConnection(connstr);
            SqlCommand com = new SqlCommand(query, conn);
            com.Parameters.Add("@imagename", SqlDbType.VarBinary).Value = ImageName;
            conn.Open();
            com.ExecuteNonQuery();
            conn.Close();
}
Posted
Updated 13-May-11 6:49am
v3

Here is the answer.
Sergey Chepurin.
 
Share this answer
 
Try these steps:
1. Open connection
2. Prepare a command with a select query
3. Execute command, get data in a dataset close connection.
4. Bind the fields of dataset table to the grid - one would be image field
 
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