DataSet

Any application will have just one DataSet which will contain one or more DataTables.
A DataSet provides you with the ability to create multiple tables and fill them with data from different sources and enforce relationships between pairs of tables.
The DataSet represents a complete set of data including tables, constraints and relationships among the tables.
A dataset is a multi-tabled disconnected cache of data.
The structure is similar to a relational database (tables, rows, columns, constraints, relationships).
You can store any type of object in a DataSet, including forms, controls and custom objects.
You should work with a dataset when you are working with multiple tables.


Typed or Untyped ?

Datasets can either be typed or untyped.
Typed Datasets - is first derived from the base Dataset class and then uses information in an XML source file (.xsd) to generate a new class.
Untyped Datasets - has no corresponding built-in schema. The table, rows and columns etc are only exposed as collections. A web service that returns an object of type System.Data.Dataset returns an untyped dataset.


Creating a DataSet Object

Dim objDataSet As System.Data.DataSet 
objDataSet = New System.Data.DataSet
objDataSet.DataSetName = "MyDataSet"

Alternatively you could pass the name of the dataset string directly to the constructor

Dim objDataSet = New System.Data.DataSet("MyDataSet") 

If the name of the DataSet is not specified then the defualt name "NewDataSet" will be used.


Detecting Changes

You can use the GetChanges method to return a DataSet that contains just the changes.
You should then check for errors in each DataTable by examining the HasErrors property
If a DataTable has errors you should use the GetErrors method to return an array of DataRows that contain errors.
On each row you can examine the RowError property for more information.
Once the errors have been corrected Merge the two DataSets together
Call the DataAdapter.Update method
DataSet.AcceptChanges or DataSet.RejectChanges

Dim objDataSetChanges As System.Data.DataSet 
objDataSetChanges = objDataSet.GetChanges(DataRowState.Modified)

If objDataSetChanges.HasErrors = True Then
   For Each objDataTable In objDataSetChanged.Tables
      If objDataTable.HasErrors = True Then

      End If
   Next objDataTable
End If

microsoft excel docs

Properties

CaseSensitiveTrue if string comparisons are case sensitive.
DataSetNameThe name of this DataSet object.
DefaultViewManagerReturns a DataViewManager object allowing you to create custom search and filter settings for the DataTable objects in this DataSet.
EnforceConstraintsTrue if constraint rules are enforced when attempting an update opreation.
ExtendedPropertiesReturns the PropertyCollection object used to store custom information about this DataSet.
HasErrorsReturns True if there are errors in any of the DataTable objects in this DataSet.
LocaleThe CultureInfo onject containing the locale information used to compare strings in this DataSet,.
NamespaceThe namespace for this DataSet, used when importing or exprting XML data.
PrefixThe XML prefix for the DataSet namespace.
RelationsReturns the collection of DataRelation objects.
TablesReturns the collection of child DataTable objects.

Methods

AcceptChangesCommits all changes to this DataSet after it was loaded or since the most recent AcceptChanges method.
ClearClears all the data in the DataSet.
CloneCreates a cloned DataSet that contains the identical structure, tables and relationships as the current one.
CopyCreates a DataSet that has both the same structure and the same data as the current one.
GetChangesGets a DataSet that contains all the changes made to the current one since it was loaded or since the most recent AcceptChanges method, optionally filtered using the DataRowState argument.
GetXmlreturns the XML representation of the contents of the DataSet.
HasChangesReturns True if the DataSet has changed. It takes an optional DataRowState argument that lets you check for modified, inserted or deleted rows only.
InferXmlSchemaInfers the XML schema from the TextReader or from the file into the DataSet.
MergeMerges the current DataSet with another DataSet, a DataTable or an array of DataRows.
ReadXmlReads an XML schema and data into the DataSet
ReadXmlSchemaReads an XML schema into the DataSet
RejectChangesRejects all changes to this DataSet after it as loaded or since the most recent AcceptChanges method.
ResetResets the DataSet to its original state.
WriteXmlWrites the XML schema and data from the current DataSet.
WriteXMLSchemaWrites the current DataSet's structure as an XML schema

Events

MergeFailedFires when two DataSet objects being merged have the same primary key value and the EnforceConstraints property is True.

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext