Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataSet Class

 

Represents an in-memory cache of data.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)


[SerializableAttribute]
public class DataSet : MarshalByValueComponent, IListSource, 
	IXmlSerializable, ISupportInitializeNotification, ISupportInitialize, 
	ISerializable

NameDescription
System_CAPS_pubmethodDataSet()

Initializes a new instance of the DataSet class.

System_CAPS_protmethodDataSet(SerializationInfo, StreamingContext)

This API supports the product infrastructure and is not intended to be used directly from your code. Initializes a new instance of a DataSet class that has the given serialization information and context.

System_CAPS_protmethodDataSet(SerializationInfo, StreamingContext, Boolean)

This API supports the product infrastructure and is not intended to be used directly from your code. Initializes a new instance of the DataSet class.

System_CAPS_pubmethodDataSet(String)

Initializes a new instance of a DataSet class with the given name.

NameDescription
System_CAPS_pubpropertyCaseSensitive

Gets or sets a value indicating whether string comparisons within DataTable objects are case-sensitive.

System_CAPS_pubpropertyContainer

Gets the container for the component.(Inherited from MarshalByValueComponent.)

System_CAPS_pubpropertyDataSetName

Gets or sets the name of the current DataSet.

System_CAPS_pubpropertyDefaultViewManager

Gets a custom view of the data contained in the DataSet to allow filtering, searching, and navigating using a custom DataViewManager.

System_CAPS_pubpropertyDesignMode

Gets a value indicating whether the component is currently in design mode.(Inherited from MarshalByValueComponent.)

System_CAPS_pubpropertyEnforceConstraints

Gets or sets a value indicating whether constraint rules are followed when attempting any update operation.

System_CAPS_protpropertyEvents

Gets the list of event handlers that are attached to this component.(Inherited from MarshalByValueComponent.)

System_CAPS_pubpropertyExtendedProperties

Gets the collection of customized user information associated with the DataSet.

System_CAPS_pubpropertyHasErrors

Gets a value indicating whether there are errors in any of the DataTable objects within this DataSet.

System_CAPS_pubpropertyIsInitialized

Gets a value that indicates whether the DataSet is initialized.

System_CAPS_pubpropertyLocale

Gets or sets the locale information used to compare strings within the table.

System_CAPS_pubpropertyNamespace

Gets or sets the namespace of the DataSet.

System_CAPS_pubpropertyPrefix

Gets or sets an XML prefix that aliases the namespace of the DataSet.

System_CAPS_pubpropertyRelations

Get the collection of relations that link tables and allow navigation from parent tables to child tables.

System_CAPS_pubpropertyRemotingFormat

Gets or sets a SerializationFormat for the DataSet used during remoting.

System_CAPS_pubpropertySchemaSerializationMode

Gets or sets a SchemaSerializationMode for a DataSet.

System_CAPS_pubpropertySite

Gets or sets an System.ComponentModel.ISite for the DataSet.(Overrides MarshalByValueComponent.Site.)

System_CAPS_pubpropertyTables

Gets the collection of tables contained in the DataSet.

NameDescription
System_CAPS_pubmethodAcceptChanges()

Commits all the changes made to this DataSet since it was loaded or since the last time AcceptChanges was called.

System_CAPS_pubmethodBeginInit()

Begins the initialization of a DataSet that is used on a form or used by another component. The initialization occurs at run time.

System_CAPS_pubmethodClear()

Clears the DataSet of any data by removing all rows in all tables.

System_CAPS_pubmethodClone()

Copies the structure of the DataSet, including all DataTable schemas, relations, and constraints. Does not copy any data.

System_CAPS_pubmethodCopy()

Copies both the structure and data for this DataSet.

System_CAPS_pubmethodCreateDataReader()

Returns a DataTableReader with one result set per DataTable, in the same sequence as the tables appear in the Tables collection.

System_CAPS_pubmethodCreateDataReader(DataTable[])

Returns a DataTableReader with one result set per DataTable.

System_CAPS_protmethodDetermineSchemaSerializationMode(SerializationInfo, StreamingContext)

Determines the SchemaSerializationMode for a DataSet.

System_CAPS_protmethodDetermineSchemaSerializationMode(XmlReader)

Determines the SchemaSerializationMode for a DataSet.

System_CAPS_pubmethodDispose()

Releases all resources used by the MarshalByValueComponent.(Inherited from MarshalByValueComponent.)

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources.(Inherited from MarshalByValueComponent.)

System_CAPS_pubmethodEndInit()

Ends the initialization of a DataSet that is used on a form or used by another component. The initialization occurs at run time.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from MarshalByValueComponent.)

System_CAPS_pubmethodGetChanges()

Gets a copy of the DataSet that contains all changes made to it since it was loaded or since AcceptChanges was last called.

System_CAPS_pubmethodGetChanges(DataRowState)

Gets a copy of the DataSet containing all changes made to it since it was last loaded, or since AcceptChanges was called, filtered by DataRowState.

System_CAPS_pubmethodSystem_CAPS_staticGetDataSetSchema(XmlSchemaSet)

This API supports the product infrastructure and is not intended to be used directly from your code. Gets a copy of XmlSchemaSet for the DataSet.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetObjectData(SerializationInfo, StreamingContext)

Populates a serialization information object with the data needed to serialize the DataSet.

System_CAPS_protmethodGetSchemaSerializable()

This API supports the product infrastructure and is not intended to be used directly from your code. Returns a serializable T:System.Xml.Schema.XMLSchema instance.

System_CAPS_protmethodGetSerializationData(SerializationInfo, StreamingContext)

This API supports the product infrastructure and is not intended to be used directly from your code. Deserializes the table data from the binary or XML stream.

System_CAPS_pubmethodGetService(Type)

Gets the implementer of the IServiceProvider.(Inherited from MarshalByValueComponent.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetXml()

Returns the XML representation of the data stored in the DataSet.

System_CAPS_pubmethodGetXmlSchema()

Returns the XML Schema for the XML representation of the data stored in the DataSet.

System_CAPS_pubmethodHasChanges()

Gets a value indicating whether the DataSet has changes, including new, deleted, or modified rows.

System_CAPS_pubmethodHasChanges(DataRowState)

Gets a value indicating whether the DataSet has changes, including new, deleted, or modified rows, filtered by DataRowState.

System_CAPS_pubmethodInferXmlSchema(Stream, String[])

Applies the XML schema from the specified Stream to the DataSet.

System_CAPS_pubmethodInferXmlSchema(String, String[])

Applies the XML schema from the specified file to the DataSet.

System_CAPS_pubmethodInferXmlSchema(TextReader, String[])

Applies the XML schema from the specified TextReader to the DataSet.

System_CAPS_pubmethodInferXmlSchema(XmlReader, String[])

Applies the XML schema from the specified XmlReader to the DataSet.

System_CAPS_protmethodInitializeDerivedDataSet()

This API supports the product infrastructure and is not intended to be used directly from your code. Deserialize all of the tables data of the DataSet from the binary or XML stream.

System_CAPS_protmethodIsBinarySerialized(SerializationInfo, StreamingContext)

Inspects the format of the serialized representation of the DataSet.

System_CAPS_pubmethodLoad(IDataReader, LoadOption, DataTable[])

Fills a DataSet with values from a data source using the supplied IDataReader, using an array of DataTable instances to supply the schema and namespace information.

System_CAPS_pubmethodLoad(IDataReader, LoadOption, FillErrorEventHandler, DataTable[])

Fills a DataSet with values from a data source using the supplied IDataReader, using an array of DataTable instances to supply the schema and namespace information.

System_CAPS_pubmethodLoad(IDataReader, LoadOption, String[])

Fills a DataSet with values from a data source using the supplied IDataReader, using an array of strings to supply the names for the tables within the DataSet.

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodMerge(DataRow[])

Merges an array of DataRow objects into the current DataSet.

System_CAPS_pubmethodMerge(DataRow[], Boolean, MissingSchemaAction)

Merges an array of DataRow objects into the current DataSet, preserving or discarding changes in the DataSet and handling an incompatible schema according to the given arguments.

System_CAPS_pubmethodMerge(DataSet)

Merges a specified DataSet and its schema into the current DataSet.

System_CAPS_pubmethodMerge(DataSet, Boolean)

Merges a specified DataSet and its schema into the current DataSet, preserving or discarding any changes in this DataSet according to the given argument.

System_CAPS_pubmethodMerge(DataSet, Boolean, MissingSchemaAction)

Merges a specified DataSet and its schema with the current DataSet, preserving or discarding changes in the current DataSet and handling an incompatible schema according to the given arguments.

System_CAPS_pubmethodMerge(DataTable)

Merges a specified DataTable and its schema into the current DataSet.

System_CAPS_pubmethodMerge(DataTable, Boolean, MissingSchemaAction)

Merges a specified DataTable and its schema into the current DataSet, preserving or discarding changes in the DataSet and handling an incompatible schema according to the given arguments.

System_CAPS_protmethodOnPropertyChanging(PropertyChangedEventArgs)

Raises the OnPropertyChanging event.

System_CAPS_protmethodOnRemoveRelation(DataRelation)

Occurs when a DataRelation object is removed from a DataTable.

System_CAPS_protmethodOnRemoveTable(DataTable)

Occurs when a DataTable is removed from a DataSet.

System_CAPS_protmethodRaisePropertyChanging(String)

Sends a notification that the specified DataSet property is about to change.

System_CAPS_pubmethodReadXml(Stream)

Reads XML schema and data into the DataSet using the specified System.IO.Stream.

System_CAPS_pubmethodReadXml(Stream, XmlReadMode)

Reads XML schema and data into the DataSet using the specified System.IO.Stream and XmlReadMode.

System_CAPS_pubmethodReadXml(String)

Reads XML schema and data into the DataSet using the specified file.

System_CAPS_pubmethodReadXml(String, XmlReadMode)

Reads XML schema and data into the DataSet using the specified file and XmlReadMode.

System_CAPS_pubmethodReadXml(TextReader)

Reads XML schema and data into the DataSet using the specified System.IO.TextReader.

System_CAPS_pubmethodReadXml(TextReader, XmlReadMode)

Reads XML schema and data into the DataSet using the specified System.IO.TextReader and XmlReadMode.

System_CAPS_pubmethodReadXml(XmlReader)

Reads XML schema and data into the DataSet using the specified System.Xml.XmlReader.

System_CAPS_pubmethodReadXml(XmlReader, XmlReadMode)

Reads XML schema and data into the DataSet using the specified System.Xml.XmlReader and XmlReadMode.

System_CAPS_pubmethodReadXmlSchema(Stream)

Reads the XML schema from the specified Stream into the DataSet.

System_CAPS_pubmethodReadXmlSchema(String)

Reads the XML schema from the specified file into the DataSet.

System_CAPS_pubmethodReadXmlSchema(TextReader)

Reads the XML schema from the specified TextReader into the DataSet.

System_CAPS_pubmethodReadXmlSchema(XmlReader)

Reads the XML schema from the specified XmlReader into the DataSet.

System_CAPS_protmethodReadXmlSerializable(XmlReader)

This API supports the product infrastructure and is not intended to be used directly from your code. Ignores attributes and returns an empty DataSet.

System_CAPS_pubmethodRejectChanges()

Rolls back all the changes made to the DataSet since it was created, or since the last time DataSet.AcceptChanges was called.

System_CAPS_pubmethodReset()

Clears all tables and removes all relations, foreign constraints, and tables from the DataSet. Subclasses should override Reset to restore a DataSet to its original state.

System_CAPS_protmethodShouldSerializeRelations()

Gets a value indicating whether Relations property should be persisted.

System_CAPS_protmethodShouldSerializeTables()

Gets a value indicating whether Tables property should be persisted.

System_CAPS_pubmethodToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.(Inherited from MarshalByValueComponent.)

System_CAPS_pubmethodWriteXml(Stream)

Writes the current data for the DataSet using the specified System.IO.Stream.

System_CAPS_pubmethodWriteXml(Stream, XmlWriteMode)

Writes the current data, and optionally the schema, for the DataSet using the specified System.IO.Stream and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

System_CAPS_pubmethodWriteXml(String)

Writes the current data for the DataSet to the specified file.

System_CAPS_pubmethodWriteXml(String, XmlWriteMode)

Writes the current data, and optionally the schema, for the DataSet to the specified file using the specified XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

System_CAPS_pubmethodWriteXml(TextWriter)

Writes the current data for the DataSet using the specified TextWriter.

System_CAPS_pubmethodWriteXml(TextWriter, XmlWriteMode)

Writes the current data, and optionally the schema, for the DataSet using the specified TextWriter and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

System_CAPS_pubmethodWriteXml(XmlWriter)

Writes the current data for the DataSet to the specified XmlWriter.

System_CAPS_pubmethodWriteXml(XmlWriter, XmlWriteMode)

Writes the current data, and optionally the schema, for the DataSet using the specified XmlWriter and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

System_CAPS_pubmethodWriteXmlSchema(Stream)

Writes the DataSet structure as an XML schema to the specified System.IO.Stream object.

System_CAPS_pubmethodWriteXmlSchema(Stream, Converter<Type, String>)

Writes the DataSet structure as an XML schema to the specified System.IO.Stream object.

System_CAPS_pubmethodWriteXmlSchema(String)

Writes the DataSet structure as an XML schema to a file.

System_CAPS_pubmethodWriteXmlSchema(String, Converter<Type, String>)

Writes the DataSet structure as an XML schema to a file.

System_CAPS_pubmethodWriteXmlSchema(TextWriter)

Writes the DataSet structure as an XML schema to the specified TextWriter object.

System_CAPS_pubmethodWriteXmlSchema(TextWriter, Converter<Type, String>)

Writes the DataSet structure as an XML schema to the specified TextWriter.

System_CAPS_pubmethodWriteXmlSchema(XmlWriter)

Writes the DataSet structure as an XML schema to an XmlWriter object.

System_CAPS_pubmethodWriteXmlSchema(XmlWriter, Converter<Type, String>)

Writes the DataSet structure as an XML schema to the specified XmlWriter.

NameDescription
System_CAPS_pubeventDisposed

Adds an event handler to listen to the Disposed event on the component.(Inherited from MarshalByValueComponent.)

System_CAPS_pubeventInitialized

Occurs after the DataSet is initialized.

System_CAPS_pubeventMergeFailed

Occurs when a target and source DataRow have the same primary key value, and EnforceConstraints is set to true.

The DataSet, which is an in-memory cache of data retrieved from a data source, is a major component of the ADO.NET architecture. The DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects. You can also enforce data integrity in the DataSet by using the UniqueConstraint and ForeignKeyConstraint objects. For further details about working with DataSet objects, see DataSets, DataTables, and DataViews.

Whereas DataTable objects contain the data, the DataRelationCollection allows you to navigate though the table hierarchy. The tables are contained in a DataTableCollection accessed through the Tables property. When accessing DataTable objects, note that they are conditionally case sensitive. For example, if one DataTable is named "mydatatable" and another is named "Mydatatable", a string used to search for one of the tables is regarded as case sensitive. However, if "mydatatable" exists and "Mydatatable" does not, the search string is regarded as case insensitive. For more information about working with DataTable objects, see Creating a DataTable.

A DataSet can read and write data and schema as XML documents. The data and schema can then be transported across HTTP and used by any application, on any platform that is XML-enabled. You can save the schema as an XML schema with the WriteXmlSchema method, and both schema and data can be saved using the WriteXml method. To read an XML document that includes both schema and data, use the ReadXml method.

In a typical multiple-tier implementation, the steps for creating and refreshing a DataSet, and in turn, updating the original data are to:

  1. Build and fill each DataTable in a DataSet with data from a data source using a DataAdapter.

  2. Change the data in individual DataTable objects by adding, updating, or deleting DataRow objects.

  3. Invoke the GetChanges method to create a second DataSet that features only the changes to the data.

  4. Call the Update method of the DataAdapter, passing the second DataSet as an argument.

  5. Invoke the Merge method to merge the changes from the second DataSet into the first.

  6. Invoke the AcceptChanges on the DataSet. Alternatively, invoke RejectChanges to cancel the changes.

System_CAPS_noteNote

The DataSet and DataTable objects inherit from MarshalByValueComponent, and support the ISerializable interface for remoting. These are the only ADO.NET objects that can be remoted.

System_CAPS_noteNote

Classes inherited from DataSet are not finalized by the garbage collector, because the finalizer has been suppressed in DataSet. The derived class can call the ReRegisterForFinalize method in its constructor to allow the class to be finalized by the garbage collector.

The following example consists of several methods that, combined, create and fill a DataSet from the Northwind database.

using System;
using System.Data;
using System.Data.SqlClient;

namespace Microsoft.AdoNet.DataSetDemo
{
    class NorthwindDataSet
    {
        static void Main()
        {
            string connectionString = GetConnectionString();
            ConnectToData(connectionString);
        }

        private static void ConnectToData(string connectionString)
        {
            //Create a SqlConnection to the Northwind database.
            using (SqlConnection connection =
                       new SqlConnection(connectionString))
            {
                //Create a SqlDataAdapter for the Suppliers table.
                SqlDataAdapter adapter = new SqlDataAdapter();

                // A table mapping names the DataTable.
                adapter.TableMappings.Add("Table", "Suppliers");

                // Open the connection.
                connection.Open();
                Console.WriteLine("The SqlConnection is open.");

                // Create a SqlCommand to retrieve Suppliers data.
                SqlCommand command = new SqlCommand(
                    "SELECT SupplierID, CompanyName FROM dbo.Suppliers;",
                    connection);
                command.CommandType = CommandType.Text;

                // Set the SqlDataAdapter's SelectCommand.
                adapter.SelectCommand = command;

                // Fill the DataSet.
                DataSet dataSet = new DataSet("Suppliers");
                adapter.Fill(dataSet);

                // Create a second Adapter and Command to get
                // the Products table, a child table of Suppliers. 
                SqlDataAdapter productsAdapter = new SqlDataAdapter();
                productsAdapter.TableMappings.Add("Table", "Products");

                SqlCommand productsCommand = new SqlCommand(
                    "SELECT ProductID, SupplierID FROM dbo.Products;",
                    connection);
                productsAdapter.SelectCommand = productsCommand;

                // Fill the DataSet.
                productsAdapter.Fill(dataSet);

                // Close the connection.
                connection.Close();
                Console.WriteLine("The SqlConnection is closed.");

                // Create a DataRelation to link the two tables
                // based on the SupplierID.
                DataColumn parentColumn =
                    dataSet.Tables["Suppliers"].Columns["SupplierID"];
                DataColumn childColumn =
                    dataSet.Tables["Products"].Columns["SupplierID"];
                DataRelation relation =
                    new System.Data.DataRelation("SuppliersProducts",
                    parentColumn, childColumn);
                dataSet.Relations.Add(relation);
                Console.WriteLine(
                    "The {0} DataRelation has been created.",
                    relation.RelationName);
            }
        }

        static private string GetConnectionString()
        {
            // To avoid storing the connection string in your code, 
            // you can retrieve it from a configuration file.
            return "Data Source=(local);Initial Catalog=Northwind;"
                + "Integrated Security=SSPI";
        }
    }
}

.NET Framework
Available since 1.1

This type is safe for multithreaded read operations. You must synchronize any write operations.

Return to top
Show:
© 2016 Microsoft