I want to update the data in database but As I add the code Dim cb As New OleDb.OleDbCommandBuilder(da)
and MsgBox("Data updated")
in the code it generate error
where is wrong in the following code
Imports System.Data
Public Class Form1
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim da1 As OleDb.OleDbDataAdapter
Dim sql As String
Dim inc As Integer
Dim MaxRows As Integer
Dim cb As New OleDb.OleDbCommandBuilder
Dim cmd As New OleDb.OleDbCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
inc = 0
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\database.mdb"
sql = "Select * From Table1"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "table1")
MaxRows = ds.Tables("table1").Rows.Count
NavigateRecords()
End Sub
Private Sub _Next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _Next.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
Private Sub NavigateRecords()
TextBox1.Text = ds.Tables("table1").Rows(inc).Item(0)
TextBox2.Text = ds.Tables("table1").Rows(inc).Item(1)
End Sub
Private Sub Pvs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pvs.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
[B]Private Sub updt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updt.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("table1").Rows(inc).Item(0) = TextBox1.Text
ds.Tables("table1").Rows(inc).Item(1) = TextBox2.Text
da.Update(ds, "table1")
MsgBox("Data updated")[/B]
End Sub
End Class