Updating database using dataadapter

For more information see Generating Commands with Command Builders.The Update method retrieves rows from the table listed in the first mapping before performing an update.The way the architecture works with the Data Adapter is that you can make any changes you want to the filled Data Set, and it won't affect the database until you call the Update method.When Update is called, the Data Adapter will attempt to execute each query (UPDATE, INSERT, DELETE) on every row of the Data Set that has been updated, inserted, and deleted.

You can avoid building Command objects manually by using Command Builder.

The Sql Data Adapter uses the Connection object of the .

The Insert Command , the Update Command , and the Delete Command properties of the Sql Data Adapter Object update the database with the data modifications, that are run on a Data Set object.

As you can see from listing 5-48, I created a filled Data Set and created a new Data Row using the Data Table. After creating a Data Row, I set its column values and called the Data Adapter's Update method and displayed data in the Data Grid.

I added new rows to the Customers table with Customer Id, Customer Name, and Company Name (named Tst ID, Lana Jackob, and Mindcracker Inc., respectively). Adding data using a Data Adapter's Update method Listing 5-49 shows an example that edits row data.

Leave a Reply