I am looking for a solution to retrieve the hex I am storing in my VersionNum column of my database which is of type (timestamp, not null). I am using a SQL Server database.
| VersionNum (timestamp, not null) |
|---|
| 0x0000000000007DA1 |
My model class:
public class Message : BoBase
{
public int MessageId { get; set; }
public string MessageText { get; set; }
public int OrderBy { get; set; }
public DateTime BeginDate { get; set; }
public DateTime EndingDate { get; set; }
public bool IsModal { get; set; }
public byte[] VersionNum { get; set; }
}
My DataObject method GetMessages:
List<Message> messages = new List<Message>();
using (SqlConnection conn = new SqlConnection(connectionString))
{
using (SqlCommand cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "uspMessages_GetList";
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
messages.Add(new Message
{
MessageId = Convert.ToInt32(dr["MessageId"].ToString()),
MessageText = dr["Message"].ToString(),
OrderBy = Convert.ToInt32(dr["orderBy"].ToString()),
IsModal = Convert.ToBoolean(dr["IsModal"]),
BeginDate = Convert.ToDateTime(dr["BeginDate"]),
EndingDate = Convert.ToDateTime(dr["EndingDate"]),
VersionNum = (byte[])dr["VersionNum"]
});
}
}
}
}
return messages;
When this query returns with data, it is only returning '{byte[8]}' for the VersionNum column rather than the hex (0x0000000000007DA1) stored in it.
I am wondering if I am not assigning it in my DataReader correctly or there is a method I am missing to get the value of the timestamp type column correctly?
SqlDataReaderdocumentation? There's aGetBytesmethod that would seem appropriate.