Page 1 of 1

Passing DateTime in MSStoredProc

Posted: Wed 02 Sep 2009 22:58
by rojash
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]

Posted: Thu 03 Sep 2009 10:08
by Dimon
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.