HOW TO STORE GRIDVIEW FILEUPLOAD CONTROLS IN TO DATABASE USING C#

Posted by qvg200286 under ASP.NET on 1/3/2013 | Points: 10 | Views : 1637 | Status : [Member] | Replies : 2
HI ALL,
I HAVE GRID VIEW DESIGN WITH FILE UPLOAD CONTROLS IN FORM BUT HOW CAN I STORE INTO DATABASE IN BUTTON CLICK

please any one help me, i am new to dot net.

THANKS,
RAMESH




Responses

Posted by: Ankitsrist on: 1/3/2013 [Member] Starter | Points: 25

Up
0
Down
u can use this code to store file in DB
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";
}
}

}
}


qvg200286, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 1/3/2013 [Member] Starter | Points: 25

Up
0
Down
Hi....
Refer the below link to upload image in to database......
http://www.dotnetcode.in/2012/06/upload-and-download-file-from-database.html

qvg200286, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response