Cascading Primary Keys

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
OK I'm really confused atm!

I haven't done any programming for a month or so, things are starting to get rusty ;)

I have 3 tables, and these are the primary keys in each:

TableA: OrderNo

TableB: StockNo, OrderNo

TableC: LineNo, OrderNo, StockNo


When I add a new row to TableB after adding a row to TableA, it cascades OrderNo OK, and I can set the StockNo.

When I add a new row to TableC after adding the row to TableB, it doesn't pull across the OrderNo and StockNo.


(a) Yes I have pulled across the correct relation (grandfather -> father -> child)
(b) I've checked both relations and they have the same settings.
(c) I've checked the relationships on the SQL server and they have the same settings.

when I add the rows, all I simply do is:

bindingsource.endedit()
bindingsource.addnew()

I think this is one of those silly questions, but I can't for the life of me work it out.
Any help appriciated!
 
OK - just to confuse the matter (or maybe not)

I put some fake data in, and manually added the key(s) myself. This works great when "browsing" the data, and everything relates how it should.

However, what I am trying to achieve is for the app to automatically fill in the primary key information when a new row is added......an example of what I'm trying to do.

Enter row to A .... PK 12345 (orderNo) - TableA is saved before....
Enter row to B .... PK 1 (stockno) , PK 12345 (orderNo) - TableB is NOT saved before....
Enter row to C .... PK 102 (lineNo), PK 12345 (orderNo), PK 1 (stockNo)

The stockNo is actually an incremental number I put in for the rowID. All it does is look at the top value in the grid and add 1 to it to get the next value for the next row... The StockNo always starts at 1 for each new OrderNo
Its the process of adding the "current" orderNo and stockNo to the row being entered into tableC.
 
Last edited:
When I add a new row to TableB after adding a row to TableA, it cascades OrderNo OK, and I can set the StockNo.
So set the stockno, then endedit the TableB bindingsource.. THEN addnew on tableC

otherwise it wont have the relation in the table, only in the BS internal list, which is fine until you endedit the parent, and it destroys the child

You set your relations to be cascading types, yes?
 

Latest posts

Back
Top