Export (0) Print
Expand All

DataSet.Tables Property

Gets the collection of tables contained in the DataSet.

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

Property Value

The DataTableCollection contained by this DataSet; otherwise a null value if no DataTable objects exist.

Remarks

To add tables to the collection, use Add method of the DataTableCollection. To remove tables, use the Remove method.

Example

[Visual Basic, C#, C++] The following example returns the DataSet object's DataTableCollection, and prints the columns and rows in each table.

[Visual Basic] 
Private Sub PrintRows(ByVal myDataSet As DataSet)
   Dim myTable As DataTable
   Dim myRow As DataRow
   Dim myColumn As DataColumn
   ' For each table in the DataSet, print the row values.
   For Each myTable in myDataSet.Tables
      For Each myRow In myTable.Rows
         For Each myColumn in myTable.Columns
            Console.WriteLine(myRow(myColumn))
         Next myColumn
      Next myRow
   Next myTable
End Sub

[C#] 
private void PrintRows(DataSet myDataSet){
   // For each table in the DataSet, print the row values.
   foreach(DataTable myTable in myDataSet.Tables){
      foreach(DataRow myRow in myTable.Rows){
         foreach (DataColumn myColumn in myTable.Columns){
            Console.WriteLine(myRow[myColumn]);
         }
      }
   }
}

[C++] 
private:
 void PrintRows(DataSet* myDataSet){
    // For each table in the DataSet, print the row values.
    System::Collections::IEnumerator* myEnum = myDataSet->Tables->GetEnumerator();
    while (myEnum->MoveNext())
    {
       DataTable* myTable = __try_cast<DataTable*>(myEnum->Current);
       System::Collections::IEnumerator* myEnum1 = myTable->Rows->GetEnumerator();
       while (myEnum1->MoveNext())
       {
          DataRow* myRow = __try_cast<DataRow*>(myEnum1->Current);
          System::Collections::IEnumerator* myEnum2 = myTable->Columns->GetEnumerator();
          while (myEnum2->MoveNext())
          {
             DataColumn* myColumn = __try_cast<DataColumn*>(myEnum2->Current);
             Console::WriteLine(myRow->Item[myColumn]);
          }
       }
    }
 }

[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

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

Show:
© 2014 Microsoft