Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Update using ADOQuery in Delphi 5

delphi

  • Please log in to reply
2 replies to this topic

#1 blanketstacker

blanketstacker

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 22 August 2008 - 02:32 PM

Hi

I am pulling my hair out, I am trying to update a table using an ado query, I am using Delphi 5 as a front end and the DB is Access 2003, I have written the app in access and it works fine but I thought I would try to write a front end in Delphi. I will endeavour to explain what I am trying to do

I want to update two columns of dates (The data type is text)
The dates represent testing dates(LastTested and DueTesting)
The dates are 91 days appart
I want to update LastTested to the current date and DueTesting 91 days later

my coding idea is roughly as follows
ADOConnection1.Connected :=True;
With ADOQuery1 do
begin
SQL.Clear;
SQL.Text :='Update MCPTestDetails Set LastTested := (:dteparam) and DueTesting := (:dteparam2)  Where DueTesting = (;dteParam) ';
Parameters.ParamByName('dteparam').Value := DateToStr(Monthcalendar1.Date);
Parameters.ParamByName('dteparam2').Value := DateToStr((Monthcalendar1.Date)+91);
ExecSQL;
Post;
close;
end; 
ADOConnection1.Connected :=False;

I keep getting an error message that the parameter is incorrectly defined any help would be much appreciated. I have used the ParamsByName in the past with ADOQuerys but never as an update and never using multiple parameters

Edited by WingedPanther, 23 August 2008 - 06:20 AM.
add code tags

  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 23 August 2008 - 06:23 AM

Your SQL statement is invalid. SQL doesn't have a := operator. Try this instead:
ADOConnection1.Connected :=True;
With ADOQuery1 do
begin
SQL.Clear;
SQL.Text :='Update MCPTestDetails Set LastTested = '+DateToStr(Monthcalendar1.Date)+' and DueTesting = '+DateToStr((Monthcalendar1.Date)+91)+'  Where DueTesting = (;dteParam) ';
ExecSQL;
Post;
close;
end; 
ADOConnection1.Connected :=False;
You'll have to play around with whether Access requires single quotes around dates, or any other special formatting. Using a showmessage to view the SQL you're about to send, and testing it in Access is a VERY helpful strategy.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 blanketstacker

blanketstacker

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 26 August 2008 - 03:23 AM

Hi WingedPanther

Many thanks for that it was very helpful
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download