Dataadapter InsertCommand - OLEDB Data Source

OleDbDataAdapter provides the communication between the Dataset and the Data Source with the help of OleDbConnection Object . The InsertCommand in OleDbDataAdapter Object manages to insert the data in the specified Data Source .

In the following Source Code shows how to insert data in the Data Source using OleDbDataAdapter and OleDbCommand object. Open a connection to the Data Source with the help of OleDbConnection object and create an OleDbCommand object with insert SQL statement, and assign the OleDbCommand to the SqlDataAdapter's InsertCommand.

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')"
            oledbAdapter.InsertCommand = New OleDbCommand(sql, connection)
            MsgBox("Row(s) Inserted !! ")
        Catch ex As Exception
        End Try
    End Sub
End Class