SiteMap  | About    

How to C# ADO.NET OleDbCommand - ExecuteNonQuery

The ExecuteNonQuery() is one of the most frequently used method in OleDbCommand Object and is used for executing statements that do not returns result sets. The ExecuteNonQuery() performs Data Definition tasks as well as Data Manipulation tasks also.


The Data Definition tasks like creating Stored Procedures, Views etc. perform by the ExecuteNonQuery() . Also Data Manipulation tasks like Insert , Update , Delete etc. perform by the ExecuteNonQuery().

The following C# example shows how to use the method ExecuteNonQuery() through OleDbCommand Object.

using System;
using System.Windows.Forms;
using System.Data.OleDb; 

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            string connetionString = null;
            OleDbConnection cnn ;
            OleDbCommand cmd ;
            string sql = null;

			connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"
			sql = "Your SQL Statement Here"

            cnn = new OleDbConnection(connetionString);
                MessageBox.Show("Connection Opened ");
                cmd = new OleDbCommand(sql, cnn);
                MessageBox.Show (" ExecuteNonQuery in OleDbConnection executed !!");
            catch (Exception ex)
                MessageBox.Show("Can not open connection ! " + ex.ToString());
} (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.