Page 1 of 1

date format in query result (SQL-Server)

Posted: Sat 27 Apr 2013 06:48
by vkattila
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

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

Posted: Mon 29 Apr 2013 07:36
by AndreyZ
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';

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

Posted: Mon 29 Apr 2013 08:02
by vkattila
I specified prNativeClient but I got an exception (Required provider is not installed) when calling UniConnection.Connect

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

Posted: Mon 29 Apr 2013 11:23
by AndreyZ
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.

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

Posted: Mon 06 May 2013 19:36
by vkattila
I installed the native client (and upgraded to UNIDAC 5), and now everything works fine.
thanks,
Attila

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

Posted: Wed 08 May 2013 13:40
by AndreyZ
It is good to see that the problem was solved. If any other questions come up, please contact us.