hi i tried to display image from sql table to gridview but its not displaying this s my code to bind gridview with sql table records..
sql.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblsession.Text = "Welcome" + Convert.ToString(Session["UName"]);
sessionimage();
}
}
private void sessionimage()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
try
{
string UName = (string)Session["UName"];
SqlDataAdapter Adp = new SqlDataAdapter("select Photo from TBL_PBLogin where UName='"+ UName +"'", con);
DataTable Dt = new DataTable();
con.Open();
Adp.Fill(Dt);
gridviewphoto.DataSource = Dt;
gridviewphoto.DataBind();
con.Close();
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
sql.aspx
45 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Carlos kambuiPosted Jun 12, 2015, 4:22 AM
Vincent Maverick DuranoPosted Jun 1, 2015, 3:37 AM
That wont work for his case as he is storing the image as binary in the database. Please try to read the entire post again.
Thanks,
Vinz
S SreelakshmiPosted Jun 1, 2015, 2:52 AM
Nanhe SiddiquePosted May 27, 2015, 11:41 PM
Deepak RatanPosted May 21, 2015, 12:55 AM
Vincent Maverick DuranoPosted May 20, 2015, 11:45 AM
Deepak RatanPosted May 20, 2015, 10:41 AM
Vincent Maverick DuranoPosted May 20, 2015, 10:29 AM
Deepak RatanPosted May 20, 2015, 10:14 AM
Deepak RatanPosted May 20, 2015, 10:04 AM
Vincent Maverick DuranoPosted May 20, 2015, 10:00 AM
Deepak RatanPosted May 20, 2015, 9:54 AM
Vincent Maverick DuranoPosted May 20, 2015, 9:49 AM
Deepak RatanPosted May 20, 2015, 9:24 AM
Vincent Maverick DuranoPosted May 20, 2015, 9:15 AM
And when you debug the ProcessRequest() method never get hit?
Can you try referencing the path like this:
Deepak RatanPosted May 20, 2015, 8:54 AM
Vincent Maverick DuranoPosted May 20, 2015, 8:46 AM
Where did you put your Handler? based on your code your Handler file should be in the same location where your page is located.
Deepak RatanPosted May 20, 2015, 8:36 AM
Vincent Maverick DuranoPosted May 20, 2015, 8:19 AM
You are almost there. Just include the EmpID in your query:
SqlDataAdapter Adp = new SqlDataAdapter("select EmpID,Photo from TBL_PBLogin where EmpID='" + EmpID + "'", con);
Vincent Maverick DuranoPosted May 20, 2015, 8:17 AM
The error is pretty much self-explanatory. That means the Id field isn't in your select query. You need to replace that with the unique identifier that holds your Images. In other words replace the ID with the primary key of your table where your image is stored.
So for example if you have this table:
Deepak RatanPosted May 20, 2015, 8:05 AM
Deepak RatanPosted May 20, 2015, 7:54 AM
Vincent Maverick DuranoPosted May 20, 2015, 7:48 AM
You need to pass the ID to your handler. It should look like this:
<asp:Image ID="Image" runat="server" ImageUrl='<%# "Handler.ashx?id=" + Eval("Id") %>' />
Upendra Pratap ShahiPosted May 20, 2015, 6:41 AM
rajshree soniPosted May 20, 2015, 5:15 AM
Deepak RatanPosted May 20, 2015, 1:40 AM
Vincent Maverick DuranoPosted May 19, 2015, 10:17 AM
Deepak RatanPosted May 19, 2015, 10:14 AM
Dipankar BiswasPosted May 19, 2015, 10:14 AM
{
if (up_load_new_img.PostedFile.ContentLength > 0)
{
s1 = Path.GetFileName(up_load_new_img.FileName);
path = Server.MapPath("file_upload") + "/" + s1;
up_load_new_img.SaveAs(path);
}
SqlConnection ronicon = new SqlConnection(strConnString);
ronicon.Open();
SqlCommand ronicom = new SqlCommand("sp_up_img", ronicon);
ronicom.CommandType = CommandType.StoredProcedure;
ronicom.Connection = ronicon;
ronicom.Parameters.AddWithValue("@usr_name", lb1.Text);
ronicom.Parameters.AddWithValue("@usr_upload_image", s1);
ronicom.ExecuteNonQuery();
ronicom.Dispose();
save_and_show();
ronicon.Close();
}
Vincent Maverick DuranoPosted May 19, 2015, 10:10 AM
Deepak RatanPosted May 19, 2015, 10:05 AM
Deepak RatanPosted May 19, 2015, 10:02 AM
Vincent Maverick DuranoPosted May 19, 2015, 10:01 AM
Deepak RatanPosted May 19, 2015, 9:59 AM
Dipankar BiswasPosted May 19, 2015, 9:48 AM
Vincent Maverick DuranoPosted May 19, 2015, 9:45 AM
Vincent Maverick DuranoPosted May 19, 2015, 9:42 AM
Deepak RatanPosted May 19, 2015, 9:40 AM
Deepak RatanPosted May 19, 2015, 9:35 AM
Vincent Maverick DuranoPosted May 19, 2015, 9:30 AM
Deepak RatanPosted May 19, 2015, 9:27 AM
Vincent Maverick DuranoPosted May 19, 2015, 9:26 AM
Dipankar BiswasPosted May 19, 2015, 9:18 AM
Deepak RatanPosted May 19, 2015, 8:53 AM
Dipankar BiswasPosted May 19, 2015, 8:43 AM
{
string useremail = (string)Session["useremail"];
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select user_profile_pic from tbl_user where user_email='" + useremail + "'";
sqlda = new SqlDataAdapter(str, con);
dt = new DataTable();
sqlda.Fill(dt);
sqlda.Dispose();
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}