How do you use a datagrid to view & edit child rows

garyjos

New member
Joined
Nov 17, 2005
Messages
4
Programming Experience
Beginner
Hello


What I would like to know is when you obtain child rows from another dataset/table via a relationship, is there away to place these child row's into a datagrid, where they could be edited, new row's added etc, and then save these changes back to the dataset/datatable, ready for updating the actual database?

The code I am using at the moment to obtain the child rows is shown below, I do not know how to copy the child row returned and put it into a datagrid, for editing and saving back to the dataset as explained above, could you please help?

This code below displays the child rows into a list box for reading only.
I would like to copy the child rows to a datagrid etc as explained previously.

*********************************************************
PublicSub FillPetDetails()
Dim objOwner As DataRow, objPet As DataRow
Dim strPetEntry AsString
' Clear any existing pets
lstPets.Items.Clear()
' Find the current Owner record
objOwner = objDataSet.Tables("Owners").Rows.Find( _
cboOwners.SelectedItem.ToString)
' Loop through each child record for this row,,as per
' the Owners2Pets relationship..Then,add details of
' each child row to lstPets..
ForEach objPet In objOwner.GetChildRows("Owners2Pets")
strPetEntry = objPet.Item("PetID") & ", " & _
objPet.Item("PetName") & ", " & objPet.Item("Type")
lstPets.Items.Add(strPetEntry)
Next
EndSub
*********************************************************

I would be grateful for your help please, also do you know of any good comprehensive ado.net books, which explain what you need to know/use often, in a clear way?


Thanks
Gary.
 
Back
Top