This is the simple code to save an image.Write this code on button click and make folder with name "images" in solution explorer. And "tb_description" is the name of table.
protected void btnSave_Click(object sender, EventArgs e) { cmd.CommandText = "insert into tb_description (image,description) values(@image,@description)"; cmd.Connection = con; con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ToString(); con.Open(); cmd.Parameters.Add("@description", SqlDbType.NVarChar, 2000).Value = TextBox2.Text; String Picture; String fp1; fp1 = FileUpload1.PostedFile.FileName; if (fp1.ToString() != "") { String fn1; fn1 = fp1.Substring(fp1.LastIndexOf("\\") + 1); String sp1; sp1 = Server.MapPath("images"); if (sp1.EndsWith("\\") == false) { sp1 += "\\"; } sp1 += fn1; FileUpload1.PostedFile.SaveAs(sp1); Picture = fn1; } else { Picture = "Noimage.jpg"; } cmd.Parameters.Add("@image", SqlDbType.NVarChar, 200).Value = Picture; cmd.ExecuteNonQuery(); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|