Dataset table row count - OLEDB Data Source

The DataSet in ADO.NET is a container that holds a collection of DataTable objects. Each DataTable represents a table of data with its rows and columns. The DataTableCollection within the DataSet can contain zero or more DataTable objects, allowing you to organize and manage multiple tables of data.

DataTable

Each DataTable consists of rows and columns, where each row represents a single record or data entry, and each column represents a specific attribute or field of that record. The data is stored in a tabular format, with rows representing individual records and columns representing the attributes or fields of those records.

You can perform various operations on the data within the DataTable, such as retrieving, updating, adding, or deleting rows, and accessing the values in specific columns of each row.

DataSet

The DataSet provides a disconnected data architecture, which means that the data retrieved from the data source is stored in the DataSet, allowing you to work with the data independently of the underlying database connection. This provides flexibility and allows for offline data manipulation and processing.

Full Source VB.NET
Imports System.Data.OleDb Module Module1 Sub Main() ' Connection string for the OLEDB data source Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Database.mdb" ' SQL query to retrieve data from the database Dim query As String = "SELECT * FROM TableName" ' Create a new DataSet Dim dataSet As New DataSet() ' Create a new OleDbDataAdapter Using adapter As New OleDbDataAdapter(query, connectionString) ' Fill the DataSet with data from the data source adapter.Fill(dataSet) End Using ' Get the DataTable from the DataSet Dim dataTable As DataTable = dataSet.Tables(0) ' Get the number of rows in the DataTable Dim rowCount As Integer = dataTable.Rows.Count ' Display the number of rows Console.WriteLine("Number of rows in the table: " & rowCount) ' Wait for user input before closing the console window Console.ReadLine() End Sub End Module

In the above code, we first define the connection string for the OLEDB data source and specify the SQL query to retrieve data from the table (replace "TableName" with the actual name of the table in your database).

We create a new DataSet object and a new OleDbDataAdapter. Then, we use the Fill method of the OleDbDataAdapter to populate the DataSet with data from the data source.

Next, we access the DataTable within the DataSet using the Tables property and index (in this example, we assume there is only one table in the DataSet, hence the index 0).

We retrieve the number of rows in the DataTable using the Rows.Count property and display it on the console.

Finally, we wait for user input before closing the console window.

Make sure to replace the connection string with the appropriate one for your OLEDB data source and update the SQL query and table name accordingly.