Dataset Insert

  • Thread starter Thread starter lloyd M
  • Start date Start date
L

lloyd M

Hi,

I have this function below that accepts a dataset called common, i
have added a new row to the dataset and now i am trying to save the
record to the database

My problem is that once the DS.UPDATE is called it saves the record to
the database, but then it skips directly to the end of function
instead of going to the "If common.HasErrors Then" step.

Below is the function, some one please help me, i dnt knw what is
going on

Public Function Insert_Login(ByVal common As CO_Login) As Boolean
Try
DS = New SqlDataAdapter
DS.TableMappings.Add("Users", "common")
DS.InsertCommand = GetInsertCommand()

DS.Update(common, "users")
'
' Check for table errors to see if the update failed.
'
If common.HasErrors Then
common.Tables("users").GetErrors(0).ClearErrors()
Else
common.AcceptChanges()

End If
Catch ex As Exception

End Try

End Function
 
That is probably because an exception is being thrown in the call to Update.
It then jumps down directly to the catch block - which has no code, so the
error is not logged or shown to the user.
 
If you'd rather look at HasErrors than watch for the exception, set
SqlDataAdapter.ContinueUpdateOnError to true. This is especially important
when updating multiple rows and you need to attempt all of the row updates
and report all failures to the user.

Brad Williams
 
Hi,

i did look at the hasErrors collection and also the EX object for any
errors, but there are no errors in the collection; also if there was a
error in the DS.Update(common, "users"); should it not save the record
into the table, it is saving the record ????
 
Hi Loyd,

The update saves it only when there are no concurrency or other errors and
when the rowstate of your datarow is set to a kind of changed.

It is normaly set to "not" changed by example in the first fill, after an
acceptchanges, by a correct update of a fulldatatable and after a
rejectchanges.

I hope this helps?

Cor
 
Back
Top