SQL 2005 Timestamp comparing in C# using SafeDataReader

SQL 2005 Timestamp comparing in C# using SafeDataReader

Old forum URL: forums.lhotka.net/forums/t/5142.aspx


DazedAndConfused posted on Wednesday, July 23, 2008

I have a time stamp on a SQL server table, which is set to a value of 0x00000000117A33F9. I am unable to extract this using the SafeDataReader, as it always gets returned as an empty byte array.

I have tried using GetBytes and GetValue and converting to a byte array, but can't seem to make the value change, based on the return result of the stored procedure.

How am I meant to do this in C#?

triplea replied on Wednesday, July 23, 2008

Did you add the dimension of your byte array? If not then it will be empty. The correct syntax should be:

protected byte[] _timestamp = new byte[ 8 ];   //in your Business Methods region

dr.GetBytes("TimeStamp", 0, _timestamp, 0, 8);   //in your Dataportal methods

Where _timestamp is your class member.

DazedAndConfused replied on Wednesday, July 23, 2008

Hi, Thanks for the reply, yes tried that, the byte array never changes when I look at each byte, no matter what the SQL is returning, seems to be the same as a newly inititalised byte array every time.

triplea replied on Wednesday, July 23, 2008

Sounds odd... Try running the PTracker example and inspect if that behaviour is also occuring. I would be surprised but give it a go nevertheless and let us know the result...

William replied on Thursday, July 24, 2008

I use the following via SafeDataReader. It works.

byte[] timestamp = (byte[]) dr.GetValue("Timestamp");

Copyright (c) Marimer LLC