Closed Thread
Results 1 to 3 of 3

Thread: Update using ADOQuery in Delphi 5

  1. #1
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Update using ADOQuery in Delphi 5

    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
    Code:
    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
    Last edited by WingedPanther; 08-23-2008 at 07:20 AM. Reason: add code tags

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,525
    Blog Entries
    75
    Rep Power
    144

    Re: Update using ADOQuery in Delphi 5

    Your SQL statement is invalid. SQL doesn't have a := operator. Try this instead:
    Code:
    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.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Re: Update using ADOQuery in Delphi 5

    Hi WingedPanther

    Many thanks for that it was very helpful

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MySQL Update, gives no error or update
    By bbqroast in forum PHP Development
    Replies: 5
    Last Post: 07-19-2011, 05:17 AM
  2. Update command tries to update the wrong table...
    By Shaddix in forum Visual Basic Programming
    Replies: 0
    Last Post: 01-08-2010, 08:18 AM
  3. Delphi UPX Help
    By KenTheFurry in forum Pascal and Delphi
    Replies: 6
    Last Post: 06-06-2008, 08:27 AM
  4. migration from of app delphi 2 to delphi 7
    By porno.shome in forum Pascal and Delphi
    Replies: 3
    Last Post: 04-22-2008, 08:57 AM
  5. Delphi help
    By Nefrit in forum Pascal and Delphi
    Replies: 2
    Last Post: 02-25-2008, 12:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts