date format in query result (SQL-Server)

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
vkattila
Posts: 3
Joined: Wed 27 Feb 2013 07:58

date format in query result (SQL-Server)

Post by vkattila » Sat 27 Apr 2013 06:48

Hi,

I'm migrating a Delphi projet from Oracle to MS SQL-Server, using UNIDAC...

I have a problem querying date fields : when I try to assign the field value of a date returned by the query to a TDateTime variable, .FieldByName('date_field').AsDateTime throws an exception (cannot convert unicode string to double).

My code :

d := UniQuerySelectPatient.FieldByName('date_naissance').AsDateTime;

where d is a TDate, and column date_naissance is of type datetime2(0)

nb : inspecting UniQuerySelectPatient.FieldByName('date_naissance').Value gives '1920-01-31 00:00:00'

how can I ensure that the returned fiel (in this case .FieldByName('date_naissance')) is of date (datetime) type ?

(I don't want to change the source code of my Delphi project, as I'd like to be able to access both Oracle and SQL-Server with the same code)

Thanks for any help...
Attila

AndreyZ

Re: date format in query result (SQL-Server)

Post by AndreyZ » Mon 29 Apr 2013 07:36

Hello,

This problem is caused by the OLEDB provider. The OLEDB provider returns datetime2 columns in the string format. To solve the problem, you should use the SQL Native Client provider. To use SQL Native Client, you should set the OLEDBProvider specific option to prNativeClient. Here is an example:

Code: Select all

UniConnection.SpecificOptions.Values['OLEDBProvider'] := 'prNativeClient';

vkattila
Posts: 3
Joined: Wed 27 Feb 2013 07:58

Re: date format in query result (SQL-Server)

Post by vkattila » Mon 29 Apr 2013 08:02

I specified prNativeClient but I got an exception (Required provider is not installed) when calling UniConnection.Connect

AndreyZ

Re: date format in query result (SQL-Server)

Post by AndreyZ » Mon 29 Apr 2013 11:23

If there is no SQL Server Native Client provider installed on a computer, the "Required provider is not installed" error is generated. To solve the problem, you should install the SQL Server Native Client provider.

vkattila
Posts: 3
Joined: Wed 27 Feb 2013 07:58

Re: date format in query result (SQL-Server)

Post by vkattila » Mon 06 May 2013 19:36

I installed the native client (and upgraded to UNIDAC 5), and now everything works fine.
thanks,
Attila

AndreyZ

Re: date format in query result (SQL-Server)

Post by AndreyZ » Wed 08 May 2013 13:40

It is good to see that the problem was solved. If any other questions come up, please contact us.

Post Reply