Introduction
The DataSet represents an in-memory collection of data retrieved from a data source. It can contain records of multiple tables. It is used for adding and manipulating records of a table in a disconnected environment.
The data in the DataSet can be edited programmatically. The developer can use an XML Schema to populate data in the DataSet. This DataSet schema can be created programmatically.
Properties and Methods of DataSet class
HasErrors
This property retrieves a value that indicates whether errors are present in any of the Data Table objects within a DataSet.
IsInitialized
This property retrieves a value that indicates whether the DataSet is Initialized.
Merge
Merges a DataSet, DataTable & DataRow objects into current DataSet or DataTable.
RejectChanges
This method rejects all changes made to the DataSet from the time it was created or since the last time the DataSet. AcceptChnages() method was called.
MergeFailed
Event occurs when the DataRow (target) and DataRow (source) have identical primary key value and also EnforceConstraints property is true.
The Source Code demonstrates how to merge two tables and display their records using the DataSet class.
- SqlConnection sqlconMarketing = new SqlConnection(“Data Source = MRKTING; Initial Catalog = DigiMarket; Integrated Security = SSPI;”);
- DataSet dsetProducts;
- DataSet dsetNewProducts;
- DataGridView dgvwProducts;
- SqlCommand sqlcomMarketing = new SqlCommand(“SELECT * FROM Products”, sqlconMarketing);
- SqlDataAdpater sqldaMarketing = new SqlDataAdapter(sqlcomMarketing);
- dsetProducts = new DataSet();
- sqldaMarketing.Fill(dsetProducts);
- dgvwProducts = new DataGridView();
- dgvwProducts.DataSource = dsetProducts.Tables[0];
- Button btnMerge = new Button();
- sqlcomMarketing = new SqlCommand(“SELECT * FROM NewProducts”, sqlconMarketing);
- sqldaMarketing = new SqlDataAdapter(sqlcomMarketing);
- dsetNewProducts = new DataSet();
- sqldaMarketing.Fill(dsetNewProducts);
- private void destProducts_MergeFailed(object sender, MergeFaildeEventArgs e) {
- MessageBox.Show(“Error
- while Merging…”);
- }
- private void btnMerge_Click(object sender, EventArgs e) {
- if (dsetProducts.IsInitialized && !dsetProducts.HasErrors) {
- dsetProducts.Merge(dsetNewProducts);
- dgvwProducts.DataSource = dsetProducts.Tables[0];
- }
- }

Join the conversation! Your thoughts help the community grow.