Search Tables in a Dataset OLEDB Data Source

The DataSet in ADO.NET consists of a DataTableCollection, which holds zero or more DataTable objects. Each DataTable represents a table of data within the DataSet. The data within each DataTable is organized in rows and columns, similar to a traditional database table.

Number of tables contained within the DataSet

To determine the number of tables contained within the DataSet, we can access the Tables property of the DataSet object. The Tables property returns the DataTableCollection, and we can then use the Count property of this collection to retrieve the total count of tables.

// Assuming we have a populated DataSet object named "dataset" int tableCount = dataset.Tables.Count; Console.WriteLine("Number of tables in the DataSet: " + tableCount);

By accessing the Count property of the Tables collection, we can obtain the number of DataTable objects present within the DataSet. This count represents the number of tables that have been populated with data using an OleDbDataAdapter or any other means.

In situations where you need to perform specific operations on individual tables within the DataSet, you can iterate over the DataTableCollection using a foreach loop or by accessing tables using their index. The following VB.NET source code shows how to find the tables inside the Dataset.

Full Source VB.NET
Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connetionString As String Dim connection As OleDbConnection Dim oledbAdapter As OleDbDataAdapter Dim ds As New DataSet Dim sql As String Dim i As Integer connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;" sql = "Your SQL Statement Here" connection = New OleDbConnection(connetionString) Try connection.Open() oledbAdapter = New OleDbDataAdapter(sql, connection) oledbAdapter.Fill(ds, "OLEDB Temp Table") oledbAdapter.Dispose() connection.Close() For i = 0 To ds.Tables.Count - 1 MsgBox(ds.Tables(i).TableName) Next Catch ex As Exception MsgBox("Can not open connection ! ") End Try End Sub End Class
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
sql = "Your SQL Statement Here"

You have to replace the string with your real time variables.