public void InsertMails(string From, string To, string Date, string Content, string AttachmentPath, byte[] CCD)
{
ClassLibrary.ConnectionClass.CurrentConnection.ExecuteNonReader("Insert into RecieveDirectMails([From],[To],Date,[Content],AttachmentPath,CreationDate,LastUpdatedDate,IsReviewed,LastUpdatedBy,IsDeleted,IsLocked,LockedBy,CCD) values ('" + From + "','" + To + "','" + Date + "','" + Content + "','" + AttachmentPath + "','" + DateTime.Now + "','" + DateTime.Now + "','" + "0" + "','" + "0" + "','" + "0" + "','" + "0" + "','" + "0" + "','" + CCD+ "')");
}
I am storing XML file bytes into Database but the error occurred.
Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.
Where I am doing it wrong can any one help me out .
In the database the CCD column is of datatype varbinary(MAX)
VARBINARYso it expects binary data as the name implies - but your last values provided is in double quotes ("........") so therefore it's a string and those cannot be converted automatically. Either you have the wrong datatype and it really should be a string format (e.g.VARCHAR(MAX)), or then you need to provide the data as a binary blob of data and not as a string in yourINSERTstatement