With a For-loop, we loop from 0 to the Count of the Tables collection minus one. Then we get each collection from the index value.
Module Module1
Sub Main()
Dim table1 As DataTable = New DataTable(
"patients")
table1.Columns.Add(
"name")
table1.Columns.Add(
"id")
table1.Rows.Add(
"sam", 1)
Dim table2 As DataTable = New DataTable(
"medications")
table2.Columns.Add(
"id")
table2.Columns.Add(
"medication")
table2.Rows.Add(1,
"atenolol")
table2.Rows.Add(6,
"trifluoperazine")
' Create the DataSet.
Dim set1 As DataSet = New DataSet(
"office")
set1.Tables.Add(table1)
set1.Tables.Add(table2)
' Loop over tables in the DataSet.
Dim collection As DataTableCollection = set1.Tables
For i As Integer = 0 To collection.Count - 1
' Get table.
Dim table As DataTable = collection(i)
Console.WriteLine(
"{0}: {1}", i, table.TableName)
Next
' First table.
Console.WriteLine(
"x: {0}", set1.Tables(0).TableName)
' Row count of medications table.
Console.WriteLine(
"y: {0}", set1.Tables(
"medications").Rows.Count)
End Sub
End Module
0: patients
1: medications
x: patients
y: 2