Parent and Child new row on windows forms details

Problem is that
Me.ParentBindingSource.AddNew
Me.ChildBindingSource.AddNew

then when saving:
Me.ParentBindingSource.EndEdit
will destroy child row.

My workaround is:
Store a variable stating is NewRow and/or child row data IsMissing
Then on SaveData use:
If NewRow OrElse IsChildRowMissing Then
  StoreData
End If
Me.ParentBindingSource.EndEdit
If NewRow OrElse IsChildRowMissing Then
  Using taP as New dsTableAdapters.ParentTableAdapter
     taP.Update(ds)
  End Using
  DisplayStoredData – which includes re-adding child row
End If
Continue with normal save

This link describes problem but is not much help to solution:
http://www.vbdotnetforums.com/database-general-discussion/13058-calling-endedit-causes-datarelations-fail.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: