SiteMap  | About    

C# Datset with OLEDB Data Provider

The DataSet contains the copy of the data we requested through the SQL statement. A DataSet represents a complete set of data including the tables that contain, order, and constrain the data, as well as the relationships between the tables.

We can use Dataset in combination with OleDbDataAdapter Class . Build and fill each DataTable in a DataSet with data from a data source using a DataAdapter. The C# OleDbDataAdapter object allows us to populate Data Tables 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);

                for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                    MessageBox.Show (ds.Tables[0].Rows[i].ItemArray[0] + " -- " + ds.Tables[0].Rows[i].ItemArray[1]);
            catch (Exception ex)
                MessageBox.Show("Can not open connection ! ");
} (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.