Parent-Child Table concept. [vb.net]

  • Thread starter Thread starter Hardik Shah
  • Start date Start date
H

Hardik Shah

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.
 
Hi,

Hardik Shah said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top