Avoid saving data after browse

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
shsit
Posts: 21
Joined: Thu 05 Oct 2006 11:41

Avoid saving data after browse

Post by shsit » Tue 15 Apr 2008 08:19

Hi,

I have a DBLookupComboBox and some DBEdit's with the same datasource.
When I change the value of an DBEdit, and then change the value of the Combobox, the data will be posted although the query has dsBrowse state.
I want the user to hit a button to save the changes, and the changes should be rejected if he scrolls the combobox without pressing the save-button before.

What's the best way to do this?
Thank you,
ben

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 16 Apr 2008 08:01

On changing the DBLookupComboBox value the DataSet goes in edit state. Changes are saved to the database not right away, but when the Post method is called. This method can be called implicitly, for example on moving to the next record in the dataset.

If you want to control changes completely, then set the DBLookupComboBox.DataSource value to nil. In that case for saving data to the database you can use the following code:

Code: Select all

  MyQuery.Edit;
  MyQuery.FieldByName('FiledName').AsString := DBLookupComboBox.Text;
  MyQuery.Post;

Post Reply