Click here to Skip to main content
13,048,011 members (97,715 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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();
            if (dt3.Rows.Count > 0)
                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;
     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);
     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:59pm
ravuravu 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
HashamAhmad 3-Jan-13 6:37am
are you getting an error? if yes then what is the error?
Zafar Sultan 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
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?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2017
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