Domanda

I have a table which have a time(7) type field named Shift_Start_Time

After creating the recordset RST.

I want to keep it in a timespan

TimeSpan  TT;
TT = RST.Fields("Shift_Start_Time").Value;

or keep it into milliseconds as integer

int int1;

int1 = RST.Fields("Shift_Start_Time").Value;

How can i do that? Every step i have taked it gives the similer errors. for example:

Convert.ToInt64(RST.Fields("Shift_Start_Time").Value);

"Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'."
È stato utile?

Soluzione

You have to use it as an Int64 or a DateTimeOffset. The code might look something like this:

var bytes = RST.Fields("Shift_Start_Time").Value as byte[];
var intVal = BitConverter.ToInt64(bytes, 0);
var dtOffset = new DateTimeOffset(intVal, new TimeSpan(-5, 0, 0));

In this example I've used a static -5 offset for EST in the TimeSpan. See this article for more detail.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top