I'm getting an odd error when trying to update a database through a DataAdapter.
Here is a simplified version of the problem in code:
VB Code:
Private Sub frmTemp_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cn As OleDb.OleDbConnection Dim da As OleDb.OleDbDataAdapter Dim cb As OleDb.OleDbCommandBuilder Dim ds As New DataSet() Dim dr As DataRow Dim sSql As String cn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Application.StartupPath() & "\dbAppraiser.mdb") sSql = "SELECT * From tblParticipants " & _ "ORDER BY iParticipantID" da = New OleDb.OleDbDataAdapter(sSql, cn) cb = New OleDb.OleDbCommandBuilder(da) da.Fill(ds, "tblParticipants") ds.Tables("tblParticipants").Rows(2).Item("sFirstName") = "Tom" ds.Tables("tblParticipants").Rows(2).Delete() da.Update(ds, "tblParticipants") End Sub
Now, the database connection works fine. I can read the rows from the DataSet without any problem in another section of the application.
If I comment out the line that deletes a row it works without a hitch. The database is updated, everything is happy.
However, if the delete statement is used I have been getting the following error:
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"
This error does not occur on the ...Delete() line but when the DataAdapter is updated. When I checked the DataSet the row is deleted and acts properly in all ways that I coudl tell.
The worst part is that it used to work (all of this code is of course spread through the application) but I had trouble deleting the row the user was looking at (something I assumed to do with the way I had assigned the row to a new DataRow object). However, even now that I have distilled it down to the bare minimum it still fails.
Any ideas?
Tom


Reply With Quote