Link to home
Start Free TrialLog in
Avatar of tomHanks
tomHanks

asked on

TDate

I am trying to input a date into an access db.

I have the following which doesn't work:

 with ADOQuery1 do begin
    Close;
    SQL.Clear;
    SQL.Add('INSERT INTO table1 (field,intfield,datefield) VALUES (:FIELD, :INTFIELD, :DATEFIELD)');
    Parameters.ParamByName('FIELD').Value := QuotedStr(edit1.text);
    Parameters.ParamByName('INTFIELD').Value := 10;
    Parameters.ParamByName('DATEFIELD').DataType := ftDate;
    Parameters.ParamByName('DATEFIELD').Value := '20021010';
    ExecSQL;
  end;

I get this error:



---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EOleException with message 'Application uses a value of the wrong type for the current operation'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------


Any ideas what I have to fix?
Avatar of tomHanks
tomHanks

ASKER

the solution is to use '10/10/2002' instead of 20021010

ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
u need to do the foloving

var dat:tdatetime;
begin
with ADOQuery1 do begin
  Close;
  SQL.Clear;
  SQL.Add('INSERT INTO table1 (field,intfield,datefield) VALUES (:FIELD, :INTFIELD, :DATEFIELD)');
  Parameters.ParamByName('FIELD').Value := QuotedStr(edit1.text);
  Parameters.ParamByName('INTFIELD').Value := 10;
  Parameters.ParamByName('DATEFIELD').DataType := ftString;
 
  Parameters.ParamByName('DATEFIELD').Value := strtodate('mm/dd/yyyy');  //or what ever is your comuter date format (not sql date format)

  ExecSQL;
end;
end;


u see the computer date format
with the

label1.caption:=datetostr(date);

:)







Tom Hanks! I'm your great fan... ;)
FormatDateTime('yyyy-mm-dd', TDate);