Insert data using OleDbConnection
Use ACE.OLEDB for databse connection (insert data)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Projects\Northwind.accdb;Persist Security Info=False")
Dim CmdStr As String = "insert into sample _
(emp_name,category,city) _
values ('" & TextBox2.Text & "',_
'" & TextBox3.Text & "',_
'" & TextBox4.Text & "')"
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand(CmdStr, con)
cmd.ExecuteNonQuery()
con.Close()
MsgBox("Done")
End Sub
Retrieve data using OleDbConnection
Use ACE.OLEDB for databse connection (retrieve data)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Projects\Northwind.accdb;Persist Security Info=False")
Dim Query2 As String = "select * from Sample"
Dim Da As OleDbDataAdapter, Ds As New DataSet, Dtb As New System.Data.DataTable
con.Open()
Da = New OleDbDataAdapter(Query2, con)
Da.Fill(Ds)
con.Close()
Dtb = Ds.Tables(0)
DataGridView1.DataSource = Dtb
End Sub