create child Dataset from parent Dataset?

bobk544

New member
Joined
Jan 3, 2009
Messages
3
Programming Experience
Beginner
hello can i create a child dataset from a parent dataset?

for example if i extract all of the data from a database table into parent_dataset

john doe
address1
address2
bob smith
address1
address2
mary lue
address1
address2

can i then create a child_dataset from the parent_dataset?

basically i want to loop thru the parent_dataset and for each change in name, i want to create a child_dataset and pass that

child_dataset to another process that will handle it's multiple records.

thanks very much
bobk
 
By child table i would want to create a sub table containing just 1 employee for example:

bob smith
address1
address2

thanks
bobk
 
Can you explain why exactly you need DataSets for that? The original data would all be contained in a single DataTable, whether or not that DataTable is contained in a DataSet. Wouldn't it be better to simply loop through the rows in that DataTable and pass the DataRows to this "other process"?

Assuming that you actually do need to use DataSets then there's no actual parent/child relationship here. You should just have said that you wanted to create a new DataSet for each row in the first, containing just that row. That could look something like this:
VB.NET:
Dim sourceDataSet As DataSet
Dim sourceTable As DataTable = sourceDataSet.Tables(0)
Dim newDataSet As DataSet
Dim newTable As DataTable

For Each row As DataRow In sourceTable.Rows
    newTable = sourceTable.Clone()
    newTable.ImportRow(row)

    newDataSet = New DataSet
    newDataSet.Tables.Add(newTable)

    'Use newDataSet here.
Next
 

Latest posts

Back
Top