Homepage image
RSS Feed

Sample Download : http://code.msdn.microsoft.com/How-to-use-DataAdapter-to-e1cd35c1

 

We can use DataAdapter to retrieve and update the data, and sometimes the features of DataAdapter make some specific operations easier. In this sample, we will demonstrate how to use DataAdapter to retrieve and update the data:

1. Retrieve Data

a. Use DataAdapter.AcceptChangesDuringFill Property to clone the data in database.

 If the property is set as false, AcceptChanges is not called when filling the table, and the newly added rows are treated as inserted rows. So we can use these rows to insert the new rows into the database.

b. Use DataAdapter.TableMappings Property to define the mapping between the source table and DataTable.

c. Use DataAdapter.FillLoadOption Property to determine how the adapter fills the DataTable from the DbDataReader.

When we create a DataTable, we can only writ the data from database to the current version or the original version by setting the property as the LoadOption.Upsert or the LoadOption.PreserveChanges.

2. Update table

Use DbDataAdapter.UpdateBatchSize Property to perfom batch operations.
image

You can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage http://1code.codeplex.com/.