SiteMap  | About    

How to DataAdapter CommandBuilder in OLEDB

The OleDbDataAdapter is a part of the ADO.NET Data Provider. OleDbDataAdapter is used to manage four separate Command objects. The InsertCommand , the UpdateCommand , and the DeleteCommand properties of the OleDbDataAdapter object update the database with the data modifications that are run on a DataSet object. The OleDbCommand objects that are assigned to these properties can be created manually in code or automatically generated by using the OleDbCommandBuilder object.

The OleDbCommandBuilder opens the Connection associated with the OleDbDataAdapter and makes a round trip to the server each and every time it's asked to construct the action queries. It closes the Connection when it's done. The following C# Source Code demonstrate how to use the OleDbDataAdapter object to update a OLEDB Data Source with data modifications that are run on a DataSet object that is populated with data from a table in the database using OleDbCommandBuilder Object.

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 ;
            OleDbCommandBuilder oledbCmdBuilder ;
            DataSet ds = new DataSet();
            int i = 0;
            string sql = null;
            connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;";
            connection = new OleDbConnection(connetionString);
            sql = "select * from tblUsers";
                oledbAdapter = new OleDbDataAdapter(sql, connection);
                oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
                for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                    ds.Tables[0].Rows[i].ItemArray[2] = "";
                MessageBox.Show ("Email address updates !");
            catch (Exception ex)
} (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.