【发布时间】:2017-02-21 05:14:33
【问题描述】:
我被要求为一组特定的操作(基本上是为电子商务门户插入产品信息)生成脚本,并执行生成的脚本。我面临的问题是我们将所有图像作为二进制数据存储在表中。现在我应该如何为此编写一个查询脚本,当我尝试以字符串的形式插入字节数组时,我得到了类型不匹配。这是我尝试过的。
//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.
但是二进制数据的类型错误,插入查询失败。我究竟做错了什么。 PictureBinary 列是 VarBinary(MAX)
【问题讨论】:
-
您是否可以选择使用准备好的语句而不是生成 SQL 字符串?如果您使用准备好的语句,那么 .NET 将为您处理转换。
-
我必须编写脚本并做好准备。该脚本将在稍后执行。
标签: asp.net sql-server