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).

<Grid>
    <dxg:GridControl x:Name="grid" AutoPopulateColumns="True"
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Top">
        <dxg:GridControl.View>
            <dxg:TableView NavigationStyle="Cell"/>
        </dxg:GridControl.View>
    </dxg:GridControl>
    <Button HorizontalAlignment="Left"
            VerticalAlignment="Bottom"
            Click="Button_Click">
        Save Data
    </Button>
</Grid>