SiteMap  | About    

How to DataAdapter Insert Command - OLEDB

OleDbDataAdapter provides the communication between the Dataset and the Data Source with the help of OleDbConnection Object . InsertCommand , UpdateCommand , and DeleteCommand properties of the OleDbDataAdapter are Command objects that manage updates to the data in the data source according to modifications made to the data in the DataSet.

The InsertCommand in OleDbDataAdapter Object manages to insert the data in the specified Data Source . From the following C# Source Code shows how to insert data in the Data Source using OleDbDataAdapter and OleDbCommand Object . Open a connection to the Data Source with the help of OleDbConnection object and create an OleDbCommand object with insert SQL statement, and assign the OleDbCommand to the SqlDataAdapter's InsertCommand.

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 = new OleDbDataAdapter();
            string sql = null;
            connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;";
            connection = new OleDbConnection(connetionString);
            sql = "insert into user values('user1','password1')";
                oledbAdapter.InsertCommand = new OleDbCommand(sql, connection);
                MessageBox.Show ("Row(s) Inserted !! ");
            catch (Exception ex)
} (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.