Find Tables in a Dataset - OLEDB

The DataSet contains DataTableCollection and their DataRelationCollection . The DataTableCollection contains zero or more DataTable objects. The data inside Table is in the form of Rows and Columns . The OleDbDataAdapter Object allows us to populate DataTables in a DataSet. The DataTable class is a member of the System.Data namespace within the .NET Framework class library.

ADO.NET enables you to create DataTable objects and add them to an existing DataSet. In some situations we have to find the number of tables resides in a Dataset Object . The following C# source code shows how to find the tables inside in a Dataset.

using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        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);
                oledbAdapter = new OleDbDataAdapter(sql, connection);
                oledbAdapter.Fill(ds, "OLEDB Temp Table");

                for (i = 0; i <= ds.Tables.Count - 1; i++)
                    MessageBox.Show (ds.Tables[i].TableName);

            catch (Exception ex)
                MessageBox.Show("Can not open connection ! ");
} (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About