I am using the default text editor available using the ajax control toolkit and I need to save an image that a user can paste into the editor, into the database. The column in the database is varbinary(MAX) but when I try to save I get the error below
Implicit conversion from data type nvarchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query
I then later converted the content to byte like so
var subgrantdesc = Convert.ToByte(grantdescription_editor.Content);
Then in the parameter definition I have this
var param0 = new SqlParameter();
param0.ParameterName = "@desc";
param0.SqlDbType = System.Data.SqlDbType.VarBinary;
param0.Value = subgrantdesc;
sql.Parameters.Add(param0);
However I get the error:
System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber....
The above error points to the line of code where I am converting to Byte
.
I would like to know how I can save data(images and text) entered through the editor control into the SQL server database. I also would like to know if the HTML formatting will be retained.
Any help will be appreciated.