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
date format in query result (SQL-Server)
-
AndreyZ
Re: date format in query result (SQL-Server)
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:
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)
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)
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)
I installed the native client (and upgraded to UNIDAC 5), and now everything works fine.
thanks,
Attila
thanks,
Attila
-
AndreyZ
Re: date format in query result (SQL-Server)
It is good to see that the problem was solved. If any other questions come up, please contact us.