Child rows

  • Thread starter Thread starter Nathan
  • Start date Start date
N

Nathan

Hi guys,

I need to know how to create child rows for a newly created parent row.
I've been doing it one way, but it's obviously not the right way to do it
(finally starting to cause me some problems!). Here's what I've been doing
("ParentID" is the primary key):

\\
Dim NewParent as DataRow = tblParentTable.NewRow
'<Initialize NewParent values>
tblParentTable.Rows.Add(NewParent)

Dim NewChild as DataRow = tblChildTable.NewRow
NewChild.Item("ParentID") = CInt(NewParent.Item("ParentID"))
'<Initialize other NewChild values>
tblChildTable.Rows.Add(NewChild)
//

What happens is, the dataset creates a "temporary" value for ParentID, and
that value is assigned to the child rows. So the relationship works okay
until the database is updated and then the tables refilled. On update, the
database sometimes gives a different value for ParentID than the database
had, but that value change is not carried through to the child rows.

What is the proper way to do this?

Thanks,
Nathan
 
Yes, a relation has been created. Relations have not been giving me
problems as far as deleting, updating, etc.

Miha Markic said:
Hi Nathan,

Do you have a relation in dataset between both datatables?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Nathan said:
Hi guys,

I need to know how to create child rows for a newly created parent row.
I've been doing it one way, but it's obviously not the right way to do it
(finally starting to cause me some problems!). Here's what I've been
doing ("ParentID" is the primary key):

\\
Dim NewParent as DataRow = tblParentTable.NewRow
'<Initialize NewParent values>
tblParentTable.Rows.Add(NewParent)

Dim NewChild as DataRow = tblChildTable.NewRow
NewChild.Item("ParentID") = CInt(NewParent.Item("ParentID"))
'<Initialize other NewChild values>
tblChildTable.Rows.Add(NewChild)
//

What happens is, the dataset creates a "temporary" value for ParentID,
and that value is assigned to the child rows. So the relationship works
okay until the database is updated and then the tables refilled. On
update, the database sometimes gives a different value for ParentID than
the database had, but that value change is not carried through to the
child rows.

What is the proper way to do this?

Thanks,
Nathan
 
Yes. - created in MS Access. My dataset is created via the designer against
the Access database.

Miha Markic said:
Are you dealing with autoincrement keys?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Nathan said:
Yes, a relation has been created. Relations have not been giving me
problems as far as deleting, updating, etc.
 
Back
Top