0

I need to run a stored procedure from code. One of the input parameters is rowVersion of the table. rowVersion is a byte array ( {0, 0, 0, 0, 0, 0, 13, 191} that's 0x0000000000000DBF in db). So if to add rowVersion this way :

cmd.Parameters.AddWithValue("@myPKRowversion", 0x0000000000000DBF);

my sp is working. 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. What should I do to make my sp work?

3
  • 2
    Note that uint only represents 4 bytes, not 8. Commented Jan 23, 2014 at 15:01
  • 1
    Can't really test this, but 0x0000000000000DBF is detected by the IDE as being an Int32, not a UInt32. So your working example and your first non-working example aren't the same. Does it work if you use an int instead of a uint? Commented Jan 23, 2014 at 15:03
  • @Tim solution that JonSkeet suggested is working fine in my code. But anyway you are right also. When I changed uint to Int32 my sp does not give me error also! Commented Jan 23, 2014 at 15:13

1 Answer 1

3

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...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.