468,117 Members | 1,536 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,117 developers. It's quick & easy.

"OleDbException was unhandled" When trying to enter data into MS Access database

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
Sep 15 '07 #1
0 1276

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Paul Steele | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.