Passing dateparameters as Variant

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Posts: 1
Joined: Wed 30 Aug 2006 14:41

Passing dateparameters as Variant

Post by VincentV » 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:

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);
  if (DataType = ftDate) then
    AsDate := Value
  else if (DataType = ftDateTime) then
    AsDateTime := Value
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?

Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Thu 31 Aug 2006 09:14

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

Post Reply