ADO.NET ExecuteNonQuery in OleDbCommand Object

The ExecuteNonQuery() method in the OleDbCommand Object is indeed one of the commonly used methods for executing statements that do not return a result set. It is particularly useful for performing data definition and data manipulation tasks within the database.

Similar to its usage in the SqlCommand Object, ExecuteNonQuery() in the OleDbCommand Object handles data definition tasks such as creating stored procedures and views. By using ExecuteNonQuery(), developers can execute SQL statements that create or modify database objects without expecting any data to be returned. This method enables the efficient execution of data definition tasks, allowing for the creation and modification of stored procedures, views, and other database objects.


The ExecuteNonQuery() is also used for data manipulation tasks, including inserting, updating, and deleting data within the database. It allows developers to execute SQL statements that modify the data without retrieving any result set. This method is especially useful for performing operations that directly affect the data, such as inserting new records, updating existing records, or deleting records from a table.

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

Full Source VB.NET
Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connetionString As String Dim cnn As OleDbConnection Dim cmd As OleDbCommand Dim sql As String connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;" sql = "Your SQL Statement Here" cnn = New OleDbConnection(connetionString) Try cnn.Open() cmd = New OleDbCommand(sql, cnn) cmd.ExecuteNonQuery() cmd.Dispose() cnn.Close() MsgBox(" ExecuteNonQuery in OleDbConnection executed !!") Catch ex As Exception MsgBox("Can not open connection ! ") End Try End Sub End Class

You have to replace the string with your realtime variables.

connetionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = Your mdb filename;"