我构建sql_insert_string
在Microsoft.ApplicationBlocks.Data.SqlHelper
被用来作为如下:插入字节数组到SQL Server
SqlHelper.ExecuteNonQuery(Transaction, CommandType.Text, sql_insert_string)
当我将鼠标悬停在SQL语句,它看起来象下面这样:
string sql_insert_string = "Insert into images_table(image_id, image_byte_array) values ('123', System.Byte[])
其中一个插入值是如上所示的一个字节数组。该变量在字节数组中有值,比如byte [6738]。但在构建sql_insert_string
之后,它的值为System.Byte[]
。 image_byte_array
列的类型是varbinary(max)
。该数据库是因为这样的SQL Server 2008数据库引发以下错误:
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as \"\" or [] are not allowed. Change the alias to a valid name.
您的sql字符串生成器只是在您的'byte []'类型的变量上调用'ToString()'。显示创建sql查询字符串的方法 – Fabio
您不应该*构建* SQL语句 - 您应该使用**参数**来避免SQL注入攻击! –
'SqlParameter'不仅可以节省您从SQL注入,此外你不会有这样的问题,因为所有的输入值将被正确地“转换”为SqlParameters – Fabio