DataSet Constructors

Definition

Initializes a new instance of the DataSet class.

Overloads

DataSet()

Initializes a new instance of the DataSet class.

DataSet(String)

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

DataSet(SerializationInfo, StreamingContext)
Obsolete.

Initializes a new instance of the DataSet class with serialized data.

DataSet(SerializationInfo, StreamingContext, Boolean)
Obsolete.

Initializes a new instance of the DataSet class with serialized data.

DataSet()

Source:
DataSet.cs
Source:
DataSet.cs
Source:
DataSet.cs

Initializes a new instance of the DataSet class.

C#
public DataSet();

Examples

The following example creates a new DataSet, and adds two DataTable objects to it.

VB
Private Sub CreateDataSet()
    Dim dataSet As New DataSet()

    ' Create two DataTable objects using a function.
    Dim table1 As DataTable = MakeTable("idTable1", "thing1")
    Dim table2 As DataTable = MakeTable("idTable2", "thing2")
    dataSet.Tables.Add(table1)
    dataSet.Tables.Add(table2)
    Console.WriteLine(dataSet.Tables.Count)
End Sub
 
 
Private Function MakeTable(c1Name As String, _
    c2Name As String) As DataTable
    Dim table As New DataTable
    
    ' Add two DataColumns
    Dim column As New DataColumn( _
        c1Name, System.Type.GetType("System.Integer"))
    table.Columns.Add(column)
    column = New DataColumn(c2Name, _
        System.Type.GetType("System.String"))
    MakeTable = table
End Function

Remarks

This implementation of the DataSet constructor takes no parameters, and creates a default name, "NewDataSet," for the new instance.

A name for the DataSet is required to ensure that the XML representation of the DataSet always has a name for the document element, which is the highest-level element in a schema definition.

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

DataSet(String)

Source:
DataSet.cs
Source:
DataSet.cs
Source:
DataSet.cs

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

C#
public DataSet(string dataSetName);

Parameters

dataSetName
String

The name of the DataSet.

Examples

The following example creates a new DataSet, to which two DataTable objects are added.

VB
Private Sub CreateDataSet()
    Dim  dataSet As New DataSet("aNewDataSet")

    ' Create two DataTable objects using a function.
    Dim table1 As DataTable = MakeTable("idTable1", "thing1")
    Dim table2 As DataTable = MakeTable("idTable2", "thing2")

    dataSet.Tables.Add(table1)
    dataSet.Tables.Add(table2)
    Console.WriteLine(dataSet.DataSetName, dataSet.Tables.Count)
End Sub


Private Function MakeTable(c1Name As String, c2Name As String) _
    As DataTable
    Dim table As New DataTable
    
    ' Add two DataColumns
    Dim column As New DataColumn( _
        c1Name, System.Type.GetType("System.Integer"))
    table.Columns.Add(column)
    column = New DataColumn(c2Name, _
        System.Type.GetType("System.String"))
    table.Columns.Add(column)
    MakeTable = table
End Function

Remarks

A name for the DataSet is required to ensure that the XML representation of the DataSet always has a name for the document element, which is the highest level element in a schema definition.

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

DataSet(SerializationInfo, StreamingContext)

Source:
DataSet.cs
Source:
DataSet.cs
Source:
DataSet.cs

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes a new instance of the DataSet class with serialized data.

C#
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected DataSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
C#
protected DataSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);

Parameters

info
SerializationInfo

The serialized data for the data set.

context
StreamingContext

Contextual information about the serialized stream.

Attributes

Exceptions

.NET 7 and later versions only: info contains binary data.

Remarks

Važno

Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Validate All Inputs.

Applies to

.NET 10 i druge verzije
Proizvod Verzije (Zastarjelo)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 (8, 9, 10)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

DataSet(SerializationInfo, StreamingContext, Boolean)

Source:
DataSet.cs
Source:
DataSet.cs
Source:
DataSet.cs

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes a new instance of the DataSet class with serialized data.

C#
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected DataSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, bool ConstructSchema);
C#
protected DataSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, bool ConstructSchema);

Parameters

info
SerializationInfo

The serialized data for the data set.

context
StreamingContext

Contextual information about the serialized stream.

ConstructSchema
Boolean
Attributes

Exceptions

.NET 7 and later versions only: info contains binary data.

Remarks

Važno

Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Validate All Inputs.

Applies to

.NET 10 i druge verzije
Proizvod Verzije (Zastarjelo)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 (8, 9, 10)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1