aharris2693
Programmer
From the research I have done as well as reading previious posts, I have written the following code as a sample to learn the process of reading and updating an Access DB. It all woks fine until the update command. At this point, I get the following message "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll" The new row is being added to the dataset, just not to the database. Has anyone run into this problem before? Any help would be greatly appreciated.
Dim strSQL As String
Dim strConn As String
Dim objDA As OleDb.OleDbDataAdapter
Dim objDS As New DataSet()
Dim intCounter As Integer
Dim strResult As String
Dim objCB As OleDb.OleDbCommandBuilder
Dim objRow As Data.DataRow
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='F:\DATA\USERS\HarrisAL\hoteling.mdb'"
strSQL = "Select * From Person"
objDA = New OleDb.OleDbDataAdapter(strSQL, strConn)
objCB = New OleDb.OleDbCommandBuilder(objDA)
objDA.Fill(objDS, "Person"
objRow = objDS.Tables("Person"
.NewRow
'objRow("PersonID"
= 50
objRow("FirstName"
= txtFirstName.Text
objRow("LastName"
= txtLastName.Text
objRow("Handle"
= txtHandle.Text
objRow("Password"
= txtPassword.Text
objDS.Tables("Person"
.Rows.Add(objRow)
objDA.Update(objDS, "Person"
With objDS.Tables(0)
For intCounter = 0 To .Rows.Count - 1
strResult = .Rows(intCounter).Item("FirstName"
.ToString
MsgBox(strResult)
Next
End With
End sub
Dim strSQL As String
Dim strConn As String
Dim objDA As OleDb.OleDbDataAdapter
Dim objDS As New DataSet()
Dim intCounter As Integer
Dim strResult As String
Dim objCB As OleDb.OleDbCommandBuilder
Dim objRow As Data.DataRow
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='F:\DATA\USERS\HarrisAL\hoteling.mdb'"
strSQL = "Select * From Person"
objDA = New OleDb.OleDbDataAdapter(strSQL, strConn)
objCB = New OleDb.OleDbCommandBuilder(objDA)
objDA.Fill(objDS, "Person"
objRow = objDS.Tables("Person"
'objRow("PersonID"
objRow("FirstName"
objRow("LastName"
objRow("Handle"
objRow("Password"
objDS.Tables("Person"
objDA.Update(objDS, "Person"
With objDS.Tables(0)
For intCounter = 0 To .Rows.Count - 1
strResult = .Rows(intCounter).Item("FirstName"
MsgBox(strResult)
Next
End With
End sub