string text1 = this.FileUploadFront.FileName;
string str8 = this.Session["ProductIDA"].ToString();
this.Ade = this.Session["ProductIDA"].ToString();
if (this.FileUploadplotfullP.HasFile)
{
string filename = base.Request.PhysicalApplicationPath.ToString() + ConfigurationManager.AppSettings["UploadSlidePhotoPath"].ToString();
string str10 = str8 + str5;
filename = filename + str10;
this.FileUploadFront.SaveAs(filename);
str = "SlidePhoto/" + str10;
ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
connection = new SqlConnection(this.strConnectionstring);
connection.Open();
this.cmd = new SqlCommand("update TBL_PRODUCTDETAILS Set PhotoFront='" + str + "' where ID ='" + str8 + "' ", connection);
this.cmd.ExecuteNonQuery();
}
--I have this previous code and i want to change like this code as following
try
{
Byte[] bytes = null;
if (FileUpload1.HasFile)
{
string filename = FileUpload1.PostedFile.FileName;
string filePath = Path.GetFileName(filename);
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
bytes = br.ReadBytes((Int32)fs.Length);
}
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
{
SqlCommand command = new SqlCommand(
"INSERT INTO tblImage (ImageName, Image) " +
"Values(@ImageName, @Image)", con);
command.Parameters.Add("@ImageName",
SqlDbType.NVarChar, 20).Value = txtImageName.Text;
command.Parameters.Add("@Image",
SqlDbType.Binary).Value = bytes;
con.Open();
command.ExecuteNonQuery();
}
}
catch (Exception)
{ //error }
}