Pass4sure Microsoft 70-526 certification testing
Creating DataSet Objects NS0-201 70-643 156-215.1
DataSet objects are available in the System.Data namespace and are used as an in-memory cache of the data being used in your application. DataSet objects contain DataTable objects that can be related with DataRelation objects much like the structure of a relational database.
DataSet Objects
Datasets are objects that you use to temporarily store the data that is used in your application. There are basically two distinct kinds of DataSet objects: typed, and untyped. Untyped DataSets are the standard generic instances of the DataSet class where you manually build up the DataSet definition (schema) by creating DataTable objects (untyped DataTables) and adding them to the Tables collection in the DataSet. You can access untyped DataTable and DataColumn objects through their collection indices. Typed DataSet objects derive their schema from an .xsd file and contain explicitly typed collections (such as a specific CustomersTable object).
There are three distinct ways to create DataSet objects in Visual Studio:
Declare a new DataSet object programmatically in the code editor, which results in an empty DataSet that requires creating DataTable and optional DataRelation objects to be added to the DataSet.
Use design-time tools such as the DataSet Designer and the Data Source Configuration Wizard which assists in the creation of typed DataSet objects by stepping you through the process of selecting or creating a data connection and then allowing you to select database objects available from that connection to build up a typed DataSet and have most, if not all, of the necessary code generated for you.
Drag a DataSet object from the Toolbox onto a form and use the Table and Column
Collection editors to build up the schema of your DataSet. 642-444 70-631 MB7-515
Merging DataSet Contents
You can take the contents from one DataSet (the source dataset) and merge it with the contents of another DataSet (the target dataset) using the DataSet.Merge method.
When merging datasets, the actual data is combined depending on whether a similar record exists in the DataSet into which it will be merged. For example, if you merge two datasets that both contain a record with the same primary key, the values in the target DataSet will be overwritten with the new values in the source DataSet. You can control this behavior and restrict changes from being made in the target DataSet by passing in a true or false value to the PreserveChanges flag in the Merge method. In addition to merging the actual data, when you merge two DataSets that have tables with differing schema, you can pass an optional MissingSchemaAction parameter to the Merge method that controls the behavior of the merge when the source DataSet has objects that are not currently in the target DataSet. The following are valid values for the MissingSchemaAction parameter:
Add (default) All schema items in the source DataSet are added to the target DataSet and populated.
AddWithKey All schema items and primary key settings are added to the target DataSet.
Error An exception will be thrown when the schemas in the source and target DataSets do not match.
Ignore All schema inconsistencies between the source and target DataSets are ignored.
In the following code example, the contents of the OldSalesDataSet are merged into the contents of the SalesHistoryDataSet. The PreserveChanges parameter is set to True and any schema differences will be ignored. 642-811 642-061 70-526