[英]convert byte array to hex in c#
I need to run a stored procedure from code. 我需要从代码运行存储过程。 One of the input parameters is rowVersion of the table.
输入参数之一是表的rowVersion。 rowVersion is a byte array ( {0, 0, 0, 0, 0, 0, 13, 191} that's 0x0000000000000DBF in db).
rowVersion是一个字节数组({0,0,0,0,0,0,13,191},在db中为0x0000000000000DBF)。 So if to add rowVersion this way :
因此,如果以这种方式添加rowVersion:
cmd.Parameters.AddWithValue("@myPKRowversion", 0x0000000000000DBF);
my sp is working. 我的sp正在工作。 But when I'm adding it like here:
但是当我在这里添加它时:
uint a = 0x0000000000000DBF;
cmd.Parameters.AddWithValue("@myPKRowversion", a);
or if I convert byte Array to string like: 或者如果我将字节数组转换为字符串,例如:
string a = "0x0000000000000DBF";
cmd.Parameters.AddWithValue("@myPKRowversion", a);
my sp is not working. 我的sp无法正常工作。 What should I do to make my sp work?
我该怎么做才能使我的sp正常工作?
I suggest you add it as a byte array . 我建议您将其添加为字节数组 。 For example:
例如:
byte[] bytes = new byte[] { 0, 0, 0, 0, 0, 0, 13, 191 };
cmd.Parameters.Add("@myPKRowVersion", SqlDbType.Binary).Value = bytes;
If you're trying to specify bytes, the most natural type is a byte array... 如果您要指定字节,则最自然的类型是字节数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.