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.
public partial class Form1 : Form
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());