Page 1 of 1

Passing dateparameters as Variant

Posted: Wed 30 Aug 2006 14:45
by VincentV
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:

Code: Select all

Query.Parameters.ParamByName(‘SOMEDATE’).Value := dtStartDateTime + iNumOfDays;
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:

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;
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?

Posted: Thu 31 Aug 2006 09:14
by Jackson
Behaviour of SDAC doesn't differ from ADO components when inserting value "0" as DateTime.
The result of inserting is '30.12.1899 0:00:00' both in SDAC and ADO.
Is there a way to determine the DataType of a parameter?
You can't get parameter data type if it wasn't set.
You just can determine it by using the following:

Code: Select all

  if VarType(Value) = varDate then begin
    FDataType := ftDateTime;
    // do smth
  end;