Can someone please help with this problem? I'm trying to go to the last record, make a new record, and save it the database. It just gives me "OleDbException was unhandled" error at da.Update(ds, "Phone") line. Thanks in advance.
Public Class PhoneReport
Inherits System.Windows.Forms.Form
Dim inc As Integer
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim MaxRows As Integer
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub PhoneReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tbDate.Text = Today()
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Motorola\Projects\databases\phone.mdb"
con.Open()
sql = "Select * from FinalTable"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Phone") '
'con.Close()
MaxRows = ds.Tables("Phone").Rows.Count
inc = -1
If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
End Sub
Private Sub NavigateRecords()
cbName.Text = ds.Tables("Phone").Rows(inc).Item("Name")
cbSJUG.Text = ds.Tables("Phone").Rows(inc).Item("SJUG")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("Phone").NewRow()
'dsNewRow.Item("Name") = cbName.Text
'dsNewRow.Item("SJUG") = cbSJUG.Text
'dsNewRow.Item("Date") = tbDate.Text
'dsNewRow.Item("Pass") = tbPass.Text
'dsNewRow.Item("Fail") = tbFail.Text
ds.Tables("Phone").Rows.Add(dsNewRow)
da.Update(ds, "Phone") 'THIS IS THE ERROR - OleDbException was unhandled
MsgBox("New Record added to the Database")
'btnCommit.Enabled = False
'btnAddNew.Enabled = True
'btnUpdate.Enabled = True
'btnDelete.Enabled = True
End If
End Sub
End Class