shailendra verma

shailendra verma

  • 1.3k
  • 401
  • 3.4k

implicit conversion from data type varchar to varbinary(max)

Nov 29 2018 12:40 AM
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string contentType = FileUpload1.PostedFile.ContentType;
using (Stream fs = FileUpload1.PostedFile.InputStream)
{
using (BinaryReader br = new BinaryReader(fs))
{
byte[] bytes = br.ReadBytes((Int32)fs.Length);
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
string query = "UPDATE tblFiles SET Name='" + filename.ToString() + "',ContentType='" + contentType.ToString() + "',Data='" + ((object)bytes) + "' WHERE id = '" + 1 + "'"; //Getting error
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
Response.Redirect(Request.Url.AbsoluteUri);

Answers (2)