sql := INSERT INTO FUNDSHISTPRICES (SYMBOL,ADATE, CLOSEV)
VALUES (:SYMBOL,:ADATE,:CLOSEV);
var
q : TIBCSQL;
q.SQL.Clear;
q.SQL.Text := sql;
q.AutoCommit := true
q.Prepare;
for each parameters I do that
q.ParamByName('SYMBOL').Value := 'IBM';// example
q.ParamByName('ADATE').Value := Date(); // today
q.ParamByName('CLOSEV').Value := 65.45; // any value
q.execute;
CRASH ON THE DATE FIELD
ALL PARAMETERS WORK OK BUT THE DATE CRASHES IT DOES NOT CONVERT IT IS SHOWN AS A REAL BEING CONVERTED AS STRING
LIKE 37879.000000 (whic is the date value as float)
I AM MISSING SOMETHING ?
IF I HAVE TO INPUT EACH TIME THE PARAMETER DATATYPE IT IS VERY CLUMSY BESIDES IT WORKS WITH ALL OTHER DATATYPES SO????
Thanks
PW
ps the caps is to diffrenciate the code from my message no sign of bad temper
Problem with date query parameters
Try to use the AsDate or AsDateTime property:
Code: Select all
q.ParamByName('ADATE').AsDate := Date();
ok it works if..................
I have a procedure
so using your tip I modified it as such
procedure TDBFirebirdIBDAC.SetQueryParameter(fQuery: TComponent;
const ParamName: string; aValue: Variant; const fISBlob: Boolean = false);
begin
bla bla..
if VarIsType(aValue, varDate) then
q.ParamByName(ParamName).AsDate := aValue
else
q.ParamByName(ParamName).Value := aValue;
end;
However if works only if I call it by forcing the datetype on the variant
var
Zdate : Tdate
zdate := date();
THAT DOES NOT WORK
SetQueryParameter(aquery,'ADATEPARAM',zdate)
THIS DOES
SetQueryParameter(aquery,'ADATEPARAM',Tdatetime(zdate) );
Why no idea....
thanks
PW
so using your tip I modified it as such
procedure TDBFirebirdIBDAC.SetQueryParameter(fQuery: TComponent;
const ParamName: string; aValue: Variant; const fISBlob: Boolean = false);
begin
bla bla..
if VarIsType(aValue, varDate) then
q.ParamByName(ParamName).AsDate := aValue
else
q.ParamByName(ParamName).Value := aValue;
end;
However if works only if I call it by forcing the datetype on the variant
var
Zdate : Tdate
zdate := date();
THAT DOES NOT WORK
SetQueryParameter(aquery,'ADATEPARAM',zdate)
THIS DOES
SetQueryParameter(aquery,'ADATEPARAM',Tdatetime(zdate) );
Why no idea....
thanks
PW