By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,445 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Parent-Child Table concept. [vb.net]

P: n/a
Hi,

I have created a form for sales bill information. I am using two tables, its
salient filds are as below.
1) Bill - Fields - bill_id,customer_id,tdate [ bill_id is auto
incremental ]
2) Itemtran - Fields - itemtran_id,bill_id,item_id,price [bill_id is not
allows null]

I am using datagrid for Itemtran table. in case of new bill creation , I
can't know new bill_id before updating data. As my itemtran table's field
bill_id doesn't accept null value, I have to replace bill_id . Temporary, I
set its allow null value true. But is there any proper method for above
task.

Any hints are appreciated.

Hardik Shah.
Jan 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

"Hardik Shah" <ha********@hotmail.com> wrote in message
news:eU**************@TK2MSFTNGP15.phx.gbl...
Hi,

I have created a form for sales bill information. I am using two tables,
its
salient filds are as below.
1) Bill - Fields - bill_id,customer_id,tdate [ bill_id is auto
incremental ]
2) Itemtran - Fields - itemtran_id,bill_id,item_id,price [bill_id is not
allows null]

I am using datagrid for Itemtran table. in case of new bill creation , I
can't know new bill_id before updating data. As my itemtran table's field
bill_id doesn't accept null value, I have to replace bill_id . Temporary,
I
set its allow null value true. But is there any proper method for above
task.

Ussully your pk column of the master DataTable is set to AutoIncrement and
seed to -1, so that there are temporary keys (negative ones) which will be
replaced with the real ones once you do a DataAdapter/TableAdapter.Update.

Then if there is a DataRelation between the two DataTable's
(DataSet.Relations.Add) and it's set to cascade updates (which is the
default, see also DataRelation.ChildKeyContraint.UpdateRule) then it will
auto. update the child's foreign key when the master's primary key has
changed.

So the fk for new child rows will take the temporary pk (if you bind in a
master-detail scenerio) and the fk's will also be updated with the new pk's
once the master table is updated

HTH,
Greetings

Any hints are appreciated.

Hardik Shah.

Jan 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.