Dataadapter InsertCommand - OLEDB Data Source

The OleDbDataAdapter plays a crucial role in facilitating communication between the Dataset and the Data Source, utilizing the OleDbConnection Object. Specifically, the InsertCommand property within the OleDbDataAdapter enables the management of data insertion into the specified Data Source.

The provided source code illustrates the process of inserting data into a Data Source using the OleDbDataAdapter and OleDbCommand objects. It involves establishing a connection to the Data Source using the OleDbConnection object, creating an OleDbCommand object with the appropriate insert SQL statement, and assigning the OleDbCommand to the OleDbDataAdapter's InsertCommand property.

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 connection As OleDbConnection Dim oledbAdapter As New OleDbDataAdapter Dim sql As String connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;" connection = New OleDbConnection(connetionString) sql = "insert into user values('user1','password1')" Try connection.Open() oledbAdapter.InsertCommand = New OleDbCommand(sql, connection) oledbAdapter.InsertCommand.ExecuteNonQuery() MsgBox("Row(s) Inserted !! ") Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class

In the above code, the OleDbConnection object establishes a connection to the Data Source using the provided connection string. The OleDbDataAdapter is instantiated, and the OleDbCommand object is created with the insert SQL statement and the OleDbConnection object assigned to it. The parameters for the insert command are defined and set accordingly.

After opening the connection, the ExecuteNonQuery method is called on the InsertCommand of the OleDbDataAdapter to execute the insert command against the Data Source. The number of affected rows is then displayed