Updating the database using dataset and dataadapter

Posted by / 20-Sep-2017 07:46

Updating the database using dataset and dataadapter

Please Note, If wish to ADD new rows to the Database, you will require am INSERT Command for the Data Adapter.

Original; What happens here, is the Data Adapter calls the Update command and saves the changes back to the database.

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.

Something like this :- SQLConnection connector = new SQLConnection(@"Your connection string"); SQLAdaptor Adaptor = new SQLAdaptor(); Updatecmd = new sql Db Command("UPDATE YOURTABLE SET FIELD1= @FIELD1, FIELD2= @FIELD2 WHERE ID = @ID", connector); Updatecmd.

It then reads associated statements; infers insert, update, and delete commands; and assigns new commands to insert, update, and delete properties of the Data Adapter.

It suffers from certain limitations; for example, it fails in The example above utilizes two parameters, a dataset and a table name.

The Data Set must be instantiated prior to a fill, and the statement spawns the table within the Data Set.

To test this source code create a Windows application, drop a Data Grid, and three buttons- Insert Command, Update Command, and Delete Command – to the form.

Listing 5-48 show the code on the Insert Command button-click event.

updating the database using dataset and dataadapter-31updating the database using dataset and dataadapter-10updating the database using dataset and dataadapter-6

Note: The Tables member of Data Set represents all Data Table objects attached to a Data Set. Adding a Data Row to a Data Table In this example, I'll show you how to add edit, and remove, data from the Northwind database.