Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
130
Insert two rows in an hierarchical grid (Master and child)
posted

my Access-Database has a Mastertable (Customer) with the ID-Field CostumerID und a Detailtable (Telefon) with a 1:n relationship. In the Detailtable is the field CostumerID. The CustomerID-Field in the Mastertable is autonumber.

 

There are a Dataset1.xsd, Dataset1, CustomerTableAdapter, CustomerBindingsource, TelefonTableAdapter, TelefonBindingsource and an UltraGrid1.

 

UltraGrid1.Datasource=CustomerBindingsource

AllowAddnew=true

 

Form-load-Event:

Me.CustomerTableAdapter.Fill(Me.DataSet1.Customer)

Me.TelefonTableAdapter.Fill(Me.DataSet1.Telefon)

 

Form-Closing-Event:

Me.CustomerBindingSource.EndEdit()

Me.CustomerTableAdapter.Update(Me.DataSet1.Customer)

 

Me.TelefonBindingSource.EndEdit()

Me.TelefonTableAdapter.Update(Me.DataSet1.Telefon)

 

When the program starts, all things are fine. Data are seen in the grid. My problem is:

 

I add a new Customer. The CustomerID is -1. Now I add a new telefon-row to the new customer (the CostumerID in the telefon-row is -1 too). So far so good. But if the programs ends, I get an error because of error in relationship.

 

Please, what can I do ?