?
Solved

TDate

Posted on 2003-03-18
5
Medium Priority
?
430 Views
Last Modified: 2010-04-04
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?
0
Comment
Question by:tomHanks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Author Comment

by:tomHanks
ID: 8160775
the solution is to use '10/10/2002' instead of 20021010

0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 150 total points
ID: 8161021
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
 
LVL 3

Expert Comment

by:ILE
ID: 8162392
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
 
LVL 3

Expert Comment

by:LukA_YJK
ID: 8165025
Tom Hanks! I'm your great fan... ;)
0
 

Expert Comment

by:Churo
ID: 8240579
FormatDateTime('yyyy-mm-dd', TDate);
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question