+ Reply to Thread
Results 1 to 3 of 3

Thread: Update using ADOQuery in Delphi 5

  1. #1
    Newbie blanketstacker is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    2

    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 09:20 AM. Reason: add code tags

  2. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,677
    Blog Entries
    57

    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.
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  3. #3
    Newbie blanketstacker is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    2

    Re: Update using ADOQuery in Delphi 5

    Hi WingedPanther

    Many thanks for that it was very helpful

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. C/C++ FAQ: Read this before you post!
    By v0id in forum C and C++
    Replies: 7
    Last Post: 08-05-2008, 12:08 PM
  2. migration from of app delphi 2 to delphi 7
    By porno.shome in forum Pascal/Delphi
    Replies: 3
    Last Post: 04-22-2008, 10:57 AM
  3. Update database from ASPX datagrid
    By MastaKay in forum General Programming
    Replies: 0
    Last Post: 11-20-2007, 01:42 AM
  4. PR Update
    By twalters84 in forum Search Engine Optimization
    Replies: 2
    Last Post: 10-27-2007, 09:31 PM
  5. Strange error in update app
    By McMillan0520 in forum C# Programming
    Replies: 1
    Last Post: 08-08-2007, 11:52 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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