Save Image Into DataBase

Prabhukiran345
Posted by Prabhukiran345 under C# category on | Points: 40 | Views : 522
 if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") 
{

byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(myimage, 0, (int)FileUpload1.PostedFile.ContentLength);

string myConnection1 = "Data Source=YOUR DATA SOURCE ; User ID=USERID ;Password=PASSWORD ;Initial Catalog=CATALOG ";
SqlConnection myConnection = new SqlConnection(myConnection1);
myConnection.Open();
// int i = 1;
SqlCommand storeimage = new SqlCommand("INSERT INTO Image3 values ("+TextBox1.Text+",@image)", myConnection);
storeimage.Parameters.Add("@Image", SqlDbType.Image).Value = myimage;

// myConnection.Open();
storeimage.ExecuteNonQuery();
myConnection.Close();
}

Comments or Responses

Login to post response