SQL server and datetime2

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
alemio
Posts: 12
Joined: Wed 20 May 2015 14:31

SQL server and datetime2

Post by alemio » Mon 27 Jul 2015 10:08

Hi, I'm using Builder c++ 6 and UniDAC to connect to SQL Server.
I need to handle date time values at tenth of milliseconds granularity.
If I try to insert with UniSQL
UniSQL->Params->ParamByName("EventDateTime")->Value = "2015-07-27 11:44:55.1234000";
I have this error

Implicit conversion from data type sql_variant to datetime2 is not allowed. Use the CONVERT function to run this query.'

I need to read too the data with tdatagrid but I get a TDateTime field, but it is only up to milliseconds.

This problem occurs also if I use prNativeClient. Is prOLEDB better?

Which datatype should I use for handling tenth of milliseconds granularity in c++ builder 6?

Thank you
Regards
Alessandro Miorelli

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: SQL server and datetime2

Post by azyk » Thu 30 Jul 2015 09:33

Currently, UniDAC maps the datetime2 type to TDateTimeField when using SQL Native Client. This class trims microseconds, and we can't affect this behavior at the moment. We will try to change this behavior in one of the next UniDAC versions.

The standard OLEDB Provider returns the TWideStringField type for the datetime2 data type, and a value in the format 'yyyy-mm-dd hh:mm:ss[.fffffff]' . So you can process the datetime2 data type as a string value with the WideString type using the standard OLEDB Provider.

Post Reply