Export (0) Print
Expand All

DataSet Constructor

Initializes a new instance of the DataSet class.

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

public DataSet()

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.

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

Private Sub CreateDataSet()
    Dim dataSet As DataSet = 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 DataColumn = 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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft