Search code examples
c++adoc++builderc++builder-6

ADOTable cancel updates in row before post


I have a remote database mysql, connected to the application (C++ Builder 6) using ADOConnection, and DBGrid, which is displayed data (ADOConnection-ADOTable-Dataset-DBGrid). ADOTable by default can not be edited; by clicking on the button "Edit", I write "readonly = false", and edit data.

After editing the line (for example, the cursor moved to the line above), I need to prompt the user ("Save changes? Y / N"), and when you select "No", to undo the changes. On request there is no problem. The question is how I should undo the changes (preferably still on the client, ie ADOTable or DBGrid)?


Solution

  • Okay, got it myself. Three weeks of headache, and five rows of code.

    if (DataSet->State == dsEdit || DataSet->State == dsInsert){
                int res = MessageBox(Handle, "Save changes?", "Confirm", MB_YESNO);
                if (res == IDNO){
                        DataSet->Cancel();
                        Abort();
                }
        }
    

    Also, if we click on other field, and select "No", cursor would not move. But that's not a problem for now.