How to DataAdapter Delete Command - OLEDB

OleDbDataAdapter is a part of the ADO.NET Data Provider. The OleDbDataAdapter works with the DataSet to provide a disconnected data retrieval mechanism. The OleDbDataAdapter uses the Connection object of the .NET Framework data provider to connect to a data source and Command objects to retrieve data from and resolve changes to the data source.

InsertCommand , UpdateCommand , and DeleteCommand properties of the DataAdapter are Command objects that manage updates to the data in the data source according to modifications made to the data in the DataSet. The following C# Source Code shows how to perform delete data from a database using DeleteCommand property of OleDbDataAdapter.

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 = "delete from tblusers1 where UserID = 'user1'";
                oledbAdapter.DeleteCommand = connection.CreateCommand();
                oledbAdapter.DeleteCommand.CommandText = sql;
                MessageBox.Show ("Row(s) Deleted !! ");
            catch (Exception ex)
} (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About