Update records gives an error after an edit

J

Jeff Brown

Does anyone else ever feel like just giving up!!!!!

When i edit a record and then update the database i get an error, although i
can add a new record completely.
The error is : An unhandled exception of type
'System.InvalidOperationException' occurred in system.data.dll
no additional info i can see

Here is the update code i am using
:
' Temporary DataSets to store the inserted or modified row.
Dim pdsInsertedRows, pdsModifiedRows As DataSet
' Set the menu items to indicate that a record is being edited.
Call EditState(cblnNotEditing)

' End editing on the current record.
Me.BindingContext(DsTrailers1, "equiptrailers").EndCurrentEdit()

' Copy the DataSets by getting the added or modified records from the
' original bound DataSet.
pdsInsertedRows = DsTrailers1.GetChanges(DataRowState.Added)
pdsModifiedRows = DsTrailers1.GetChanges(DataRowState.Modified)

' Check to see if there is an inserted row. If there is update DataSet.
If Not pdsInsertedRows Is Nothing Then
odbdaTrailers.Update(pdsInsertedRows)
End If
**********************************************
THE ERROE THORWS HERE ON THE END IF STAEMENT
' Check to see if there is a modified row. If there is update dataset
If Not pdsModifiedRows Is Nothing Then
odbdaTrailers.Update(pdsModifiedRows)
End If
**********************************************

' Synchronize the database
DsTrailers1.AcceptChanges()
 
M

Marina

Is there a reason you want to do the inserts and the updates completely
separately? Why bother getting the update changes and the insert changes
separately, and then updating?

If you put try/catch around the whole thing (which you should anyway, to
catch connection problems, etc), the exception object should have a more
specific message.
 
J

Jeff Brown

Will give that a try....

The insert & edit procedures i have working on the local dataset....

I figured that way changes would not be immedialtely commited and hence
prevent faulty edits.
 
J

Jeff Brown

Tried that and i get an empty message box
also tried ex as system.exception and systemexception
and System.InvalidOperationException
with the same results



Try
If Not pdsModifiedRows Is Nothing Then
odbdaTrailers.Update(pdsModifiedRows)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top