how can i insert an image into sql database and than i can i retrieve it.
i want to create an asp.net application where a student add his/her image on registration page and this image save in sql datatable and further we can use this image on other pages as required.
Loading
Deepak Kumar ChoudharyPosted Feb 28, 2014, 12:42 PM
imgeurl is a table column name
I am also attached your same website file with correction now execute
Nitin SharmaPosted Mar 1, 2014, 12:38 AM
thank you very much for your help
Nitin SharmaPosted Feb 28, 2014, 5:39 AM
i m attaching the source code with sql query page please check it and advice me how to do it
thanks in advance.
Deepak Kumar ChoudharyPosted Feb 27, 2014, 11:35 AM
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=xyz;Integrated Security=True");
con.Open();
string fpath = "\\uploads\\" + FileUpload1.FileName.ToString(); FileUpload1.PostedFile.SaveAs(Server.MapPath(fpath));
Session["user"] = TextBox1.Text;
SqlCommand cmd = new SqlCommand("insert into reg values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + fpath + "'", con); cmd.ExecuteNonQuery();
Response.Redirect("ViewProfile.aspx");
2.Now access image form database using flowing code
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=xyz;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from reg where userid='"+Session["user"].ToString()+"'", con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
Image1.ImageUrl = dr["imageurl"].ToString();