protected void Button2_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { if (FileUpload1.PostedFile.ContentType == "image/jpeg") { if (FileUpload1.PostedFile.ContentLength < 102400) { db.myconnection(); int length = FileUpload1.PostedFile.ContentLength; byte[] imagebyt = new byte[length]; HttpPostedFile img = FileUpload1.PostedFile; img.InputStream.Read(imagebyt,0,length ); SqlCommand cmd = new SqlCommand("insert into picsupload(image)values(@image)", db.sqlcon); cmd.Parameters.Add("@image", SqlDbType.Image).Value=imagebyt; cmd.ExecuteNonQuery(); Label1.Text = "inserted"; } else { Label1.Text = "select file"; } } } }
Login to post response