For fast loading of images we can store the location of the image rather than the storing the image itself. Following can be used to store image url in the database -
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string imagepath = "~/images/" + FileUpload1.PostedFile.FileName;
string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand("INSERT into Image (name, image) VALUES (@name, @image)", conn);
cmd.Parameters.AddWithValue("@name", FileUpload1.PostedFile.FileName);
cmd.Parameters.AddWithValue("@image", imagepath);
cmd.ExecuteNonQuery();
conn.Close();
}
}
Comments
Post a Comment