1

With Visual Basic in Visual Studio I am trying to select a row of type rowversion from a SQL Server database.

'version' is a column of type rowversion

SELECT [Version] FROM Employees WHERE Employee_id = 1  

Then in VB - To get value from version column

Dim myBuffer As Byte()  
Dim reader As SqlDataReader  
numRead = reader.GetBytes(0, 0, myBuffer, 0, 16)

I know there is data in mybuffer from this:

 For i = 0 To myBuffer.Length - 1  
    MsgBox(myBuffer(i).ToString())
 Next

Also myBuffer.Length = 9

But when I want to query my database with myBuffer...

cmd.Parameters.AddWithValue("version", myBuffer)

I get the error:

Procedure or function 'updatePerson' expects parameter '@version', which was not supplied.

As if myBuffer in NULL.

Does anybody know to get the rowversion out of a database and then use it in a query?

Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
Carl
  • 19
  • 1
  • 3
    [Can we please stop using `AddWithValue()`, already?](http://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/) - also, have you tried adding the param with `@version` instead of `version`? Also, what does your parameterized query/stored proc look like? – Siyual Mar 23 '17 at 14:07
  • Try explicitly stating the type, it is possible `AddWithValue` is incorrectly determining the data type - `cmd.Parameters.Add("@version", SqlDbType.Timestamp).Value = myBuffer` – GarethD Mar 23 '17 at 14:13
  • GarethD - Your answer does the trick. I did have to do ReDim Preserve myBuffer(7) – Carl Mar 23 '17 at 14:58

0 Answers0