Find Tables in a Dataset - OLEDB

In ADO.NET, the DataSet is comprised of two main components: the DataTableCollection and the DataRelationCollection. The DataTableCollection serves as a container for zero or more DataTable objects. Each DataTable within the collection represents a structured table of data, organized into rows and columns.

DataTable

The rows of a DataTable represent individual records or data entries, while the columns represent the various attributes or fields associated with the data. Together, the rows and columns form a tabular structure to store and manage data within the DataTable.

In certain scenarios, we may need to determine the number of tables present within a DataSet. To accomplish this, we can access the DataTableCollection property of the DataSet. This collection provides access to the DataTable objects contained within the DataSet, allowing us to query the count or utilize other appropriate methods to retrieve the number of tables present.

Full Source C#
using System; using System.Data; using System.Data.OleDb; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string connetionString = null; OleDbConnection connection ; OleDbDataAdapter oledbAdapter ; DataSet ds = new DataSet(); string sql = null; int i = 0; 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; i <= ds.Tables.Count - 1; i++) { MessageBox.Show (ds.Tables[i].TableName); } } catch (Exception ex) { MessageBox.Show("Can not open connection ! "); } } } }

To populate the DataTables within a DataSet, we can utilize the OleDbDataAdapter Object. The OleDbDataAdapter facilitates communication between a data source and the DataSet, enabling us to populate the DataTables with data. This object acts as a bridge, allowing us to retrieve data from the data source and fill the DataTables within the DataSet.

The DataTable class, which is a member of the System.Data namespace within the .NET Framework class library, provides various properties and methods to manage and manipulate data within the DataTable. It offers flexibility in terms of adding, deleting, and modifying rows and columns, as well as performing data-related operations.

Conclusion

ADO.NET empowers developers to create and manage DataTable objects within a DataSet. The DataSet, with its DataTableCollection and DataRelationCollection, provides a structured and relational representation of data. By using the OleDbDataAdapter, we can populate DataTables within the DataSet from a data source. The DataTable class, belonging to the System.Data namespace, offers various capabilities for working with tabular data. When necessary, we can determine the number of tables residing within a DataSet by accessing the DataTableCollection property.