Sorry for my English.
对不起我的英语不好。
I use a text file with a correct sql insert-statement for bulk loading in my test project. I apply this statement to an empty table to load data. But I faced with the problem of writing an array of bytes.
我在我的测试项目中使用带有正确sql insert-statement的文本文件进行批量加载。我将此语句应用于空表以加载数据。但是我遇到了写一个字节数组的问题。
How can I write the correct insert-statement that I used to pass an array of bytes? Will understand SQL Server 2008 an array of bytes as hex-string?
如何编写用于传递字节数组的正确insert-statement?将SQL Server 2008的字节数组理解为十六进制字符串?
Added: I need some string that I can apply to SQL Server to insert an array of bytes. Something like that:
补充:我需要一些字符串,我可以应用于SQL Server插入一个字节数组。像这样的东西:
INSERT INTO T(SomeBlobColumn) VALUES (0x666F6F)
or
INSERT INTO T(SomeBlobColumn) VALUES (CAST('666F6F' AS BINARY))
1 个解决方案
#1
2
You could try this approach (in c#):
您可以尝试这种方法(在c#中):
using(SqlCommand cmd = new SqlCommand("INSERT INTO TableName(BinaryColumn) VALUES (@InputParameter)", sqlConnection))
{
cmd.Parameters.Add("@InputParameter", SqlDbType.VarBinary, 8000).Value = byteArray;
cmd.ExecuteNonQuery();
}
#1
2
You could try this approach (in c#):
您可以尝试这种方法(在c#中):
using(SqlCommand cmd = new SqlCommand("INSERT INTO TableName(BinaryColumn) VALUES (@InputParameter)", sqlConnection))
{
cmd.Parameters.Add("@InputParameter", SqlDbType.VarBinary, 8000).Value = byteArray;
cmd.ExecuteNonQuery();
}