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?
tomHanksAsked:
Who is Participating?
 
kretzschmarConnect With a Mentor Commented:
try

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 := '2002/10/10';  //format is yyyy/mm/dd
   ExecSQL;
 end;

meikl ;-)

0
 
tomHanksAuthor Commented:
the solution is to use '10/10/2002' instead of 20021010

0
 
ILECommented:
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);

:)







0
 
LukA_YJKCommented:
Tom Hanks! I'm your great fan... ;)
0
 
ChuroCommented:
FormatDateTime('yyyy-mm-dd', TDate);
0
All Courses

From novice to tech pro — start learning today.