I have been asked to generate scripts for a certain set of operations (basically insertion of product information for an ecommerce portal), and execute the generated script. The problem I'm facing is that we are storeing all images as binary data in a table. Now how am I supposed to script a query for this, Im getting a type mismatch when I tried to insert the byte array in the form of a string. This is what I tried.
//imgbyte is the byte array containing the piucture data
StringBuilder sb=new StringBuilder();
sb.AppendLine("declare @picquery as Varchar(4000)");
sb.AppendLine("set @picquery='Insert into Picture(PictureBinary) values (''"+imgbyte.ToString() +"'')'");
sb.AppendLine("exec(@picquery)");
// sb is then passed to another module where it is executed.
But the type for the binary data is wrong and the insert query fails. What am I doing wrong. the column PictureBinary is VarBinary(MAX)