Another simple ADO query question..

Posted on 2004-11-04
Last Modified: 2010-04-04
I use an ADO query ( insert into ...) to add a record to a table, and execute using qry->ExecSQL()

If there's an index violation (duplicate key / illegal empty field etc) it throws an exception. Can't I trap that somehow? The query component has OnPostError and OnEditError but they don't get called? Or do I have to try to insert the record a different way?

Question by:andrewjb
    LVL 12

    Accepted Solution

    There is different methods to insert records
    1). You have described it ....
    2). Use the code construction:

      ADOQuery.FieldByName('NAME').AsString := EditName.Text;

    3). Use stored procedure built in the database using TADOStoredProc: you will pass the parameters and then ADOStoredProc1.ExecProc

    LVL 12

    Author Comment

    I've realised after posting that I can, of course, just try...catch around the ExecSQL. That works, but do you have an opinion as to the 'best' way to do it? Which one would trigger the OnPostError etc. events?

    LVL 12

    Expert Comment

    It really does not work:
    I tryed to debug it, posted an illegal data for a field, but an exception raises and the debuger does not go into the OnPostError ?
    I don't know why ....
    LVL 27

    Assisted Solution

    OnPostError triggers on a an open dataset,
    but as u use execsql this and near all other events are not triggered

    usual the best way would be the way u found

      //handle your error

    meikl ;-)

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now