Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Image is saved in image datatype in database help me.
string sd = "select Name,Id,Designation,Phone,Address,Salary,Place,Image from Employee where Id='"+n+"'";
            SqlDataAdapter mad = new SqlDataAdapter(sd, DbConnection.mCon);
            DataTable dt3 = new DataTable();
            mad.Fill(dt3);
            if (dt3.Rows.Count > 0)
            {
                nam=dt3.Rows[0][0].ToString();
                id=int.Parse(dt3.Rows[0][1].ToString());
                desig = dt3.Rows[0][2].ToString();
                pho = dt3.Rows[0][3].ToString();
                addr = dt3.Rows[0][4].ToString();
                sal =float.Parse(dt3.Rows[0][5].ToString());
                plac = dt3.Rows[0][6].ToString();
                Image1.ImageUrl = dt3.Rows[0][7].ToString();
            }
the below coding is insertion coding
protected void Button1_Click(object sender, EventArgs e)
{
     img_upload = "~/img/" + FileUpload1.FileName;
     FileUpload1.SaveAs(MapPath(img_upload));
     Image1.ImageUrl = img_upload;
}
protected void Button2_Click(object sender, EventArgs e)
{
     string sm = "insert into Employee values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','"+img_upload+"')";
     SqlCommand cmdn = new SqlCommand(sm, DbConnection.mCon);
     cmdn.ExecuteNonQuery();
     Response.Write("<script>alert('Employee Details Inserted')</script>");
     TextBox1.Text = TextBox2.Text = TextBox3.Text =TextBox4.Text=TextBox5.Text=TextBox6.Text=TextBox7.Text= "";
     Image1.ImageUrl = null;
}
Posted 3-Jan-13 0:59am
v3
Comments
ravuravu at 3-Jan-13 6:02am
   
i want to retrieve the image to image control
please check the line
Image1.ImageUrl = dt3.Rows[0][7].ToString();
 
and correct it
Zafar Sultan at 3-Jan-13 6:45am
   
Add a breakpoint at Image1.ImageUrl = dt3.Rows[0][7].ToString(); and tell us what is the ImageURL it returns?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

select Image from Employee where Id='yourID';
run this query in SSMS, not code behind and see what it returns? Copy the result and manually set the image URL to the result returned by your query. I am sure the path is not getting saved correctly in the database. Also check if you can see the saved file in you "img" folder and with what name?
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,963
1 OriginalGriff 6,726
2 Peter Leow 4,232
3 Zoltán Zörgő 3,769
4 Richard MacCutchan 2,558


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100