Page 1 of 1

Reading DateTime values from Access mdb

Posted: 25.09.2012, 15:54
by hstijnen
Hi,
I've an Access database with a table aTable and columns SysTime (Date/Time) and Value (float). I create the following query:

Query->SQL->Text = "SELECT SysTime, Value FROM aTable WHERE SysTime >= :from AND SysTime <= :to"
// fill in pars
Query->Params->FindParam("from")->AsDateTime = FromTime;
Query->Params->FindParam("to")->AsDateTime = ToTime;
// open
Query->Open();

That runs all OK, giving the correct number of records and the correct Value's.
double pvalue = Query->FindField("Value")->AsFloat; // correct pvalue

HOWEVER, the date/time values give only the Date part:
double tfloat = Query->FindField("SysTime")->AsFloat; // gives only integer
TDateTime Datetime = Query->FindField("SysTime")->AsDateTime; // gives only Date part

How to retrieve the full Date/Time values from Access Mdb?

Thanks in advance

Regards, Henk

Posted: 28.09.2012, 01:02
by EgonHugeist
hstijnen,

No idea why it fails, Henk. With a MsSQL Server it works fince, right? Can't test it by my selves..

Posted: 28.09.2012, 09:20
by hstijnen
With MsSQL server indeed OK.

I use way around:
SELECT SysTime, Waarde, year(SysTime) as j1, month(SysTime) as m1, day(SysTime) as d1, hour(SysTime) as h1, minute(SysTime) as n1, second(SysTime) as s1

and then
int j1 = Query->FindField("j1")->AsInteger;
int m1 = Query->FindField("m1")->AsInteger;
int d1 = Query->FindField("d1")->AsInteger;
int h1 = Query->FindField("h1")->AsInteger;
int n1 = Query->FindField("n1")->AsInteger;
int s1 = Query->FindField("s1")->AsInteger;
TDateTime dt1 = EncodeDateTime(j1, m1, d1, h1, n1, s1, 0);

Then it's OK.

Posted: 28.09.2012, 14:14
by EgonHugeist
hstijnen,

dirty workaround ): but seems to work, Henk. I have no testbase to check the issue. It might also be possible that Access assignes the values wrong to the Variants. Does it work with a ADOConnection?