插入字节数组INTO varbinary(max)记录 [英] Insert Bytes array INTO varbinary(max) record

查看:115
本文介绍了插入字节数组INTO varbinary(max)记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要插入记录varbinary(max)Byte数组中的表中,该怎么办?

I want to INSERT INTO a table in a record varbinary(max) a Byte array How can I do that?

推荐答案

使用存储过程,只需创建varbinary(max)类型的参数,然后将其插入表中即可,就像任何数据类型一样.

Using a stored procedure, just create a parameter of type varbinary(max) and insert it into the table as you would any data type.

在您的C#(或vb或任何其他代码)中,向sql命令对象添加一个参数,并将字节数组设置为参数值:

In your c# (or vb or whatever) code, add a parameter to your sql command object and set the byte array as the parameter value:

command.Parameters.AddWithValue("@parameter_name", myByteArray);

如果不使用存储过程,则可以对带参数的sql语句执行相同的操作,但是我从未尝试过这样做,因此我无法举一个例子.

If not using a stored procedure, you can probably do the same with a parameterized sql statement, but I have never tried that, so I can't give an example.

您正在使用参数化查询,这不是我的事,所以我不能保证这会起作用.但是,这里有一些代码应该可以助您一臂之力.

You are using a parameterized query, which is not my thing, so I can't guarantee this will work. But, here is some code that should get you going.

RemoteSQLcmd = New SqlCommand("INSERT INTO Table(1) Values (newid(), ProductID, @bin_value", RemoteSQLConn)
RemoteSQLcmd.Parameters.AddWithValue(@bin_value", imSource) ;

二进制值必须表示为参数(@bin_value),并且该值由AddWithValue语句设置.参数名称不必与列名称匹配.

The binary value must be represented as a parameter (@bin_value), and the value is set by the AddWithValue statement. The parameter name does not have to match the column name.

一些注意事项:我建议在您的插入语句中使用列名称,而不要取决于列位置,而且,我也不知道您所说的'table(1)'是什么意思-实际上是桌子?

A couple of notes: I would suggest using columns names in your insert statement rather than depending on column position, Also, I don't know what you mean by 'table(1)' - is that actually the name of the table?

这篇关于插入字节数组INTO varbinary(max)记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆