DataSet Property

DataTable.DataSet Property

Gets the DataSet that this table belongs to.

[Visual Basic]
Public ReadOnly Property DataSet As DataSet
[C#]
public DataSet DataSet {get;}
[C++]
public: __property DataSet* get_DataSet();
[JScript]
public function get DataSet() : DataSet;

Property Value

The DataSet that this table belongs to.

Remarks

If a control is data bound to a DataTable, and the table belongs to a DataSet, you can get to the DataSet through this property.

Example

[Visual Basic, C#, C++] The following example returns the parent DataSet of a given table through the DataSet property.

[Visual Basic] 
Private Function GetDataSetFromTable() As DataSet
    Dim myTable As DataTable

    ' Check to see if the DataGrid's DataSource property
    ' is a DataTable.
    If TypeOf dataGrid1.DataSource Is DataTable Then
        myTable = CType(DataGrid1.DataSource, DataTable)
        GetDataSetFromTable = myTable.DataSet
    Else
        return Nothing
    End If
End Function

[C#] 
private DataSet GetDataSetFromTable()
{
    DataTable myTable;
 
    // Check to see if the DataGrid's DataSource
    // is a DataTable.
    if( dataGrid1.DataSource is DataTable)
    {
        myTable = (DataTable) dataGrid1.DataSource;
        // Return the DataTable's DataSet
        return myTable.DataSet;
    }
    else
    {
        return null;
    }
}

[C++] 
private:
DataSet* GetDataSetFromTable()
{
    DataTable* myTable;
 
    // Check to see if the DataGrid's DataSource
    // is a DataTable.
    if(dynamic_cast<DataTable*>( dataGrid1->DataSource))
    {
        myTable = dynamic_cast<DataTable*> (dataGrid1->DataSource);
        // Return the DataTable's DataSet
        return myTable->DataSet;
    }
    else
    {
        return 0;
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataTable Class | DataTable Members | System.Data Namespace | DataSet

Show:
© 2016 Microsoft