well here is my sample code . What iam trying to do is to simply convert the file into binary format so i can insert it into the data table
string fileName = FileUpload1.PostedFile.FileName;
Stream strm = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(strm);
Byte[] Data = br.ReadBytes((int)strm.Length);
string fileType = FileUpload1.PostedFile.ContentType;
SqlConnection conn = new SqlConnection(connString);
conn.Open();
string sql = string.Format("Insert into FileUpload (Data,fileName,fileType) values('{0}','{1}','{2}')", Data, fileName, fileType);
Response.Write(sql);
SqlCommand command = new SqlCommand(sql, conn);
command.ExecuteNonQuery();
conn.Close();
label1.ForeColor = System.Drawing.Color.Green;
label1.Text = "uploaded!!!!";
The problem is that everytime i execute it it says " Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query."