Header Detail Example

F

Frank Py

I want to relate 2 tables in Access or SQL for a one to many. I would
like to find an example in .Net for data entry for this structure. For
example, I would like customer info at the top of the page and customer
history at the bottom. Maybe the details section can be in a editable
grid control and the customer header can be just form controls. Is there
any known code samples for what I'm trying to do?

Code examples appreciated. Thanks.
Frank
 
M

Manit Chanthavong

I think what you want is to insert the child data, with the primary ID from
the parent table.

Parent table:

ParentID Name FName

Child Table:

ID Address ParentID

Child Table 2

ID PhoneNumbers ParentID

You would perform an InsertStatment like This:

INSERT INTO ParentTable (name,Fname) VALUES

DECLARE @pid as int
SELECT @pid=@@IDENTITY -- there are better ways of doing this, for example
row locking

--- Now insert into child tables

INSERT INTO Child1 (address, parentid) VALUES('',@pid)
INSERT INTO Child1 (PhoneNumbers, parentid) VALUES('',@pid)
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top