how can i upload a file in database using asp.net & c#..
anyone please help me..

thanks

//First store your file in to a byte array like this

HttpPostedFile filPosted = filUpload.PostedFile;
int intFileLength = System.Convert.ToInt32(filPosted.ContentLength);
byte[] byteData = new byte[intFileLength];
filPosted.InputStream.Read(byteData, 0, intFileLength);

//Now use this byte array to insert your file into the Database

SqlConnection myconn = new SqlConnection("Connection String here");
string insertQry = "INSERT INTO [Pictures] ([Title], [MIMEType], [Image]) VALUES (@Title, @MIMEType, @ImageData)"
SqlCommand myCmd = new SqlCommand(insertQry, myconn);
myCmd.Parameters.AddWithValue("@Title", "ImageTitle");
myCmd.Parameters.AddWithValue("@MIMEType", "image/gif");
myCmd.Parameters.AddWithValue("@ImageData", byteData);
myconn.Open();
myCmd.ExecuteNonQuery();
myconn.Close();

//The type of your imageField in your DB table should be Image
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.