Passing dateparameters as Variant
Posted: Wed 30 Aug 2006 14:45
I am upgrading our application from ADO to SDAC. Because I want to make as few modifications to our code as possible I would like to write a wrapper for any incompatibilities I encounter.
In ADO, we had to pass all input parameters as variants, like so:
In SDAC this does not work correctly: the date is off by 2 days. (The reason for this is the Delphi date counts from 12/31/1899 and SQL Server counts from 01/01/1900.)
I tried to fix this, by deriving my own TParam from TMSParam in which the method SetAsVariant was overridden like so:
However, DataType is always ftUnknown so my solution does not work. – As a result, I have 2 questions.
- Is there a way to have the “.Value”-property interpret the date correctly?
- Is there a way to determine the DataType of a parameter?
In ADO, we had to pass all input parameters as variants, like so:
Code: Select all
Query.Parameters.ParamByName(‘SOMEDATE’).Value := dtStartDateTime + iNumOfDays;
I tried to fix this, by deriving my own TParam from TMSParam in which the method SetAsVariant was overridden like so:
Code: Select all
procedure THCParam.SetAsVariant(const Value: Variant);
begin
if (DataType = ftDate) then
AsDate := Value
else if (DataType = ftDateTime) then
AsDateTime := Value
else
inherited;
end;
- Is there a way to have the “.Value”-property interpret the date correctly?
- Is there a way to determine the DataType of a parameter?