Brades

I am trying to do the following:
  1. Retrieve a timestamp from SQL Server database as a byte array
  2. Convert the byte array back to hexidecimal
But I get different values

DAO:
scheduleItem.TimeStamp = (reader.IsDBNull(ScheduleItemBasicOrdinals.timestamp)) null : (System.Byte[])reader[ScheduleItemBasicOrdinals.timestamp];

ScheduleItemBasicOrdinals.timestamp = rdr.GetOrdinal("Timestamp");

ENTITY:
private Byte[] timeStamp;

public Byte[] TimeStamp
{
get
{
return this.timeStamp;
}

set
{
if (this.timeStamp == value)
return;

this.timeStamp = value;
}
}

ASPX.CS
public static string BytesToHex(byte[] bytes)

{
StringBuilder hexString = new StringBuilder(bytes.Length);
hexString.Append("0x");
for (int i = 0; i < bytes.Length; i++)
{
hexString.Append(bytesIdea.ToString("X2"));
}
return hexString.ToString();
}

string test = BytesToHex(currentItem.TimeStamp);

DATABASE VALUE
0x00000000001C6466

BYTE ARRAY
0 0 0 0 0 28 108 100

STRING VALUE
AAAAAAAcbGQ=

HEX VALUE AFTER CALL TO BytesToHex FUNCTION
0x00000000001C6C64

Any ideas

Thanks




Re: Visual C# General Timestamp to Hexidecimal Conversion Issue

TaylorMichaelL

Your byte array data doesn't match what the DB is saying it is. Have you confirmed that the data hasn't changed since you last looked at it If you're using SQL then the timestamp will change each time the row is modified. Did you try reading the data using GetBytes rather than retrieving it as an object

Michael Taylor - 10/19/07

http://p3net.mvps.org