Passing DateTime in MSStoredProc

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rojash
Posts: 1
Joined: Wed 02 Sep 2009 22:34
Location: Greece

Passing DateTime in MSStoredProc

Post by rojash » Wed 02 Sep 2009 22:58

Hi,
I have to call a stored procedure which includes two DateTime parameters.
I can do this interactively from within the IDE, by simply typing in the dates.
However when I do it programatically, the parameters do not appear to be passed correctly.

Code snippet:

Code: Select all

Var
  TheDespatchDate : TDateTime;
  TheReqDate : TDateTime;
begin
  TheDespatchDate:=StrToDateTime(DespatchDate);
  TheReqDate:=StrToDateTime(CustRequiredDate);
  With MSStoredProc2 do
  begin
    ParamByName('CustRequiredDate').AsDateTime:=TheReqDate;
    ParamByName('DespatchDate').AsDateTime:=TheDespatchDate;
    Execute;
  end;
end;
The debug window shows:
MSStoredProc2.ParamByName('DespatchDate').DataType => ftDateTime
MSStoredProc2.ParamByName('CustRequiredDate').DataType => ftDateTime
MSStoredProc2.ParamByName('DespatchDate').Value => '08/09/2009'
MSStoredProc2.ParamByName('CustRequiredDate').Value => '08/09/2009'

When execute is called a message is returned that DespatchDate cannot be NULL.

As I said, if I manually type these values into the Parameters page of the component, and click the Execute button, it works fine, so clearly the problem is not with the stored procedure itself.[/code][/quote]

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 03 Sep 2009 10:08

Try to call the TMSStoredProc.PrepareSQL method before setting the parameters values.
If it doesn't solve the problem, please compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.

Post Reply