typed dataset + null values + cm.EndCurrentEdit

P

Paul

Hi,

I have a typed ds which contains a single table which in turn has a number
of columns for which "min occurs = 0". The columns from this ds are bound to
a bunch of controls on a form. I am having some trouble with the
currencymanager when it comes to adding a new row, as follows;

1. Addnew method called
2. User starts entering data
3. User decides to exit form using control box (X) upper right then;
Validating event for non nullable control fires and sets cancel to true
Form Closing event fires and attempts to catch changes to ds using
the EndCurrentEdit in order to allow user the option to stop.
EndCurrentEdit causes "System.Data.NoNullAllowedException,
"Column 'PS_PhoneNumber' does not allow nulls."

Problem: if I don't call EndCurrentEdit the ds.HasChanges is False. If I do,
I get the above exception. I thought I should be able to end the edit and
check the ds.HasErrors rather than have the exception generated. I suspect I
don't understand something here. Any advice would be appreciated.

Thanks

Paul

Sample: (Hopefull enough1)

Private Sub ubtnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ubtnAdd.Click
' Add new patient record.
cmPatients.EndCurrentEdit()
cmPatients.AddNew()
End Sub

Private Sub unePhone_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles unePhone.Validating
If unePhone.Value Is System.DBNull.Value Then
Me.epPatients.SetError(unePhone, "Phone Number Must Be Entered")
e.Cancel = True
Else
Me.epPatients.SetError(unePhone, "")
End If
End Sub

Private Sub frmMaintPatients_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
' Check there are no outstanding changes which have not been sent to the DB

cmPatients.EndCurrentEdit() ''''' PROBLEM HERE!!
If dsMaintPatients.HasChanges Then
If Not DiscardUserChanges() Then
e.Cancel = True
Exit Sub
End If
End If
' Allow the form to close even if the user has become stuck in
validating events
e.Cancel = False
End Sub
 

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