The following is the sample code to show that how we can save the image in the SQL Server. we have to take the column type as IMAGE, and using the BYTE array we can save the uploaded image.
please check the following code for this.
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
con.Open();
byte[] ImgBytes = new byte[flurl.PostedFile.InputStream.Length];
flurl.PostedFile.InputStream.Read(ImgBytes, 0, ImgBytes.Length);
string qry = "Insert into Table1(ImageData) values(@ImageData)";
SqlCommand cmd = new SqlCommand(qry, con);
cmd.Parameters.AddWithValue("@ImageData", ImgBytes);
cmd.ExecuteNonQuery();
con.Close();
con.Open();
byte[] ImgBytes = new byte[flurl.PostedFile.InputStream.Length];
flurl.PostedFile.InputStream.Read(ImgBytes, 0, ImgBytes.Length);
string qry = "Insert into Table1(ImageData) values(@ImageData)";
SqlCommand cmd = new SqlCommand(qry, con);
cmd.Parameters.AddWithValue("@ImageData", ImgBytes);
cmd.ExecuteNonQuery();
con.Close();
Happy Coding!!!!!!
ThanksAnil Kumar PandeySystem ArchitectGreen Point Technology (India) Ltd.Mumbai, MaharshtraINDIA
what is package i need to import for
ReplyDeleteflurl(Saving the image in SQL Server Port)
send me responce to santosh.mca08@gmail.com
regards
santosh