How to: Post Changes to SQL Database

  • 2 minutes to read

The .Net data model implies that a control bound to a database using DbDataAdapter and DataTable objects does not immediately post changes after they have been made. Instead, changes are accumulated in the DataTable. You have to manually call a specific method to update the database. Changes you made while editing data (adding, deleting or modifying records) are saved in the grid's data source (e.g. DataTable). To post these changes to the database, you should call the data adapter's Update method.

Before calling this method, make sure that the grid control has saved all the changes made to the currently focused row. In this instance, you should call the DataViewBase.CommitEditing method.

This example shows how to post changes to a SQL database. Before data is posted to the database, the DataViewBase.CommitEditing method is called to validate the currently edited row (if any).

    <dxg:GridControl x:Name="grid" AutoPopulateColumns="True"
            <dxg:TableView NavigationStyle="Cell"/>
    <Button HorizontalAlignment="Left"
        Save Data