Net-informations.com
SiteMap  | About    

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()
        {
            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 ! ");
            }
        }
    }
}






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.