Click here to Skip to main content
Sign Up to vote bad
good
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 2 Jan '13 - 23:59
Edited 3 Jan '13 - 0:47
Tadit Dash23.1K

Comments
ravuravu - 3 Jan '13 - 6:02
i want to retrieve the image to image control please check the line Image1.ImageUrl = dt3.Rows[0][7].ToString(); and correct it
HashamAhmad - 3 Jan '13 - 6:37
are you getting an error? if yes then what is the error?
Zafar Sultan - 3 Jan '13 - 6:45
Add a breakpoint at Image1.ImageUrl = dt3.Rows[0][7].ToString(); and tell us what is the ImageURL it returns?

1 solution

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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 355
1 OriginalGriff 330
2 Arun Vasu 264
3 Tadit Dash 221
4 CPallini 203
0 Sergey Alexandrovich Kryukov 10,005
1 OriginalGriff 7,654
2 CPallini 4,171
3 Rohan Leuva 3,447
4 Maciej Los 2,974


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