I am trying to save image from fileupload control into the database
public Byte[] bytes;
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
bytes = br.ReadBytes((Int32)fs.Length);
SqlDataSource2.Update();
protected void SqlDataSource2_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters["@project_file"].Value = bytes;
}
My database project_file field is set to varbinary(MAX),
but it is throwing an error
Parameter ‘@project_file’ exceeds the size limit for the sql_variant datatype.
Please suggest some solution
This is a quote from MSDN on binary and varbinary:
varbinary(MAX)can hold an image that is ~2GB of size.Solution to your problem:
You forgot to specify the type in your code. You need to set the correct SqlDbType.
e.Command.Parameters["@project_file"].SqlDbType = SqlDbType.VarBinaryWhat you should also do i set the correct Size.