By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

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

P: 2
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
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"

sql = "Select * from FinalTable"
da = New OleDb.OleDbDataAdapter(sql, con)

da.Fill(ds, "Phone") '


MaxRows = ds.Tables("Phone").Rows.Count
inc = -1

If inc <> MaxRows - 1 Then
inc = MaxRows - 1
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


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
Share this question for a faster answer!
Share on Google+

Post your reply

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