Master Detail entering new Master + new Detail(s)???

Master Detail entering new Master + new Detail(s)???

Post by Grant Sche » Sat, 10 Oct 2009 05:10:46


Hello,

This is for Win Forms.

I have a simple master detail form with two datagridviews. Top view has a
list of "Station Lists" showing an ID and Name and the bottom is a list of
the "Stations" for the station list selected in the top. Currently, aside
from the FK to the station list ID the only other column is a text field
called "Extension".

I created the app with the wizards and then modified my bindings for the
"Station" grid view's bind source to set the datasource to the master's
(StationList) binding source and the datamember the relation created by the
wizards.

I also added an update button to the form which when I click I then make
these calls:

this.stationListTableAdapter.Update(this.sTPSRecorderDataSet);
this.stationTableAdapter.Update(this.sTPSRecorderDataSet);

This all works fine. I can select an existing "Station List" in the top
grid and then enter a new Station extension in the bottom grid and it sets
the StationListID to the station list selected in the top grid. If I then
click my update button the changes are committed to the SQL DB.

The problem I have is if I enter a new station list name in the top grid
the station list ID shows as -1 and if I then enter an extension in the
bottom it lets me do so also showing the same -1 as the FK in the bottom.
However, if I then click my update button the first update works but the
second throws an exception:

{"The INSERT statement conflicted with the FOREIGN KEY constraint
\"FK_Station_StationList1\". The conflict occurred in database
\"STPSRecorder\", table \"dbo.StationList\", column 'StationListID'.\r\nThe
statement has been terminated."}

I'm thinking I need to make some call after I update the station list table
but before I update the station table but if so I'm not sure what.

Any ideas?

Thanks!
--
Grant Schenck
 
 
 

1. Master/Detail DVWP: New Master search still shows old Detail

2. Master-detail: why doesn't detail DS automatically track row of master (i.e. :param not updated)?

I have this:
master:
SqlQuery1 <- DataSetProvider1 <- ClientDataSet1 <- DataSource1

detail:
DataSource1 <-
SqlQuery2 <- DataSetProvider2 <- ClientDataSet2 <- DataSource2

The DataSource property of SqlQuery2 is DataSource1 (making SqlQuery2
the detail and SqlQuery1 the master). The SELECT statement in SqlQuery2
contains a parameter that gets its value from the master at runtime.

I compile and execute. Code contains:
ClientDataSet1.Open;
ClientDataSet2.Open;

ClientDataSet1's first row data appears in the controls hooked up to
DataSource1, and the detail rows for that 1st row appear in the controls
that are hooked up to DataSource2.

HOWEVER as I navigate through ClientDataSet1 (master) using TDBNavigator
or TDBGrid, the data in the detail are not automatically updated... I.e.
I am expecting the visual controls hooked up to DataSource2 to change
based on the currently selected row of ClientDataSet1.

What am I doing wrong?

Thanks.

3. Master Detail Report With Master Chart and Detail Table

4. CachedUpdate in a master/detail query from another master/detail query

5. Master Detail commits the master on detail exception

6. Master/Detail - after insert new detail record

7. Master-detail: I see all the detail records if I append a detail record

8. VB Master-Details Edit (Separate Pages), Response Redirect to Master Page Databinding Issue...

9. 2nd Post: VB Master-Details Edit (Separate Pages), Response Redirect to Master Page Databinding Issue...

10. Repost: VB Master-Details Edit (Separate Pages), Response Redirect to Master Page Databinding Help...

11. Details Being manipulated in c: drive (Master-Details)

12. Master/Detail/Sub detail

13. Master Detail Error: "The master that you picked is in an incorre

14. Only highest detail in Master-detail query?

15. Concatenation of detail-records in a Master-Detail relationship