Arrays 更新查询图像

Arrays 更新查询图像,arrays,vb.net,image,visual-studio-2010,Arrays,Vb.net,Image,Visual Studio 2010,如果我尝试将图像转换为数组,然后运行更新查询并插入字符串update the transformed image matrix,则会出现错误: 未为1字节的“字符串”和“矩阵”类型定义+运算符 大小 代码是: data1 = textbox data2 = TextBox2 using ms as new MemoryStream () DirectCast (picturebox1.image, botmap) .save (ms currentFormat) image = ms.t

如果我尝试将图像转换为数组,然后运行更新查询并插入字符串update the transformed image matrix,则会出现错误:

未为1字节的“字符串”和“矩阵”类型定义+运算符 大小

代码是:

data1 = textbox 
data2 = TextBox2 
using ms as new MemoryStream () 
DirectCast (picturebox1.image, botmap) .save (ms currentFormat) 
image = ms.toArray () 
end using 
Dim param as SqlParameter () = _ new SqlParameter () {new SqlParameter ("@ data1", _ data1), new SqlParameter ("@ data2", data2), new SqlParameter ("@ image", image)}
 mcmd.commandText = "update set table column1 = '" + data1 + "', column2 '" + data1 + "'" 
 mcmd.parameters.add ("@ image", SqlDbType.varbinary, 8000) .Value = image 

如何修复它?

无论如何,您正在为代码中的image变量定义一个参数,如下所示

mcmd.parameters.add ("@image", SqlDbType.varbinary, 8000) .Value = image
因此,不要通过连接同样容易受到SQL注入攻击的值来准备查询;对已定义的参数使用参数化查询

mcmd.commandText = "update table_name set column1 = @data1, column2 = @data2, image = @image

我们如何帮助您而不看到您在代码中所做的工作?这是什么语言?发布您已经拥有的代码,以帮助人们回答您的问题。代码是:data1=textbox data2=TextBox2使用ms作为新内存Stream DirectCast picturebox1.image,botmap。将ms currentFormat image=ms.toArray保存为Dim param作为SqlParameter=u新SqlParameter{new SqlParameter@data1,data1,new SqlParameter@data2,data2,new SqlParameter@image,image}mcmd.commandText=updateset table column1='+data1+',column2'+data1+'mcmd.parameters.add@image,SqlDbType.varbinary,8000.Value=image我正在visual studio 2010中使用vb查看这篇文章。你会发现我试图更改字符串,如图所示,但编译器返回异常类型@date1 unfinedhave创建/添加了参数@date1?我在注释中给出了一个链接;请仔细查看并尝试相应的操作。很抱歉,我的意思是data1I应该找到连接字符串和数组的替代方法,有什么想法吗?不,不应该连接。而是传递具有图像字节[]的参数,如回答中所示。