Follow the code below:
var bytes = ConvertTo.Bytes(file);
int num = ctx.Database.ExecuteSqlCommand(
$"UPDATE dbo.Table" +
$"SET Video = '{bytes}' " +
$"WHERE id = {Id} ");
Follow the code to convert:
public static byte[] Bytes(HttpPostedFileBase file)
{
var length = file.InputStream.Length;
byte[] fileData = null;
using (var binaryReader = new BinaryReader(file.InputStream))
{
fileData = binaryReader.ReadBytes(file.ContentLength);
}
return fileData;
}
I get error:
The implicit conversion of the varchar data type into varbinary (max) is not allowed. Use the CONVERT function to execute this query.
Any solution?