Retrieving Child Rows

G

Glenn T. Kitchen

Dear Group,

I'm having problems retrieving the child rows of a parent row. The parent
table is Users and the child table is Addresses. I used the Schema to
create a DataRelation between the Primary Key of the parent table and a Long
Integer field of the child table. I allowed default (which defaults to
Cascade) in the relationship. The relationship is titled "drlnUserAddress".
I always get a return of 0 child rows and there are four rows in the child
table which match the parent row (0).

If anyone sees an error in my code, please let me know. Or if you can think
of things to check whereby I may be making an error. Below is the code
segment. Thank you very much!



==================== CODE SEGMENT========================

Dim UserCount As Integer
Dim ChildRows() As DataRow
Dim ChildRow As Integer
Dim ChildCount As Integer

'Change Select command - I select a particular username
Me.OleDbSelectCommand1.CommandText = "SELECT Notes, [Password], UserID,
Username, Verify FROM Users WHERE (Username = '" &
Trim(TextBox1.Text.ToString) & "')"

Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
Me.OleDbDataAdapter1.Fill(DsLoginB1)
Me.OleDbDataAdapter2.Fill(DsLoginB1)

UserCount = DsLoginB1.Users.Rows.Count
Label5.Text = UserCount.ToString

'Use just the first row of the parent results "0"
ChildRows = DsLoginB1.Users(0).GetChildRows("drlnUserAddress")

ChildCount = ChildRows.Length
Label4.Text = ChildCount.ToString

'Place the childRows field("City") in the dropdown Box
For ChildRow = 0 To ChildRows.Length - 1
DropDownList1.Items.Add(ChildRows(ChildRow).Item("City"))
Next

========== END CODE SEGMENT ===================

Thank you,

glenn
 
K

Ken Tucker [MVP]

Hi,

You have to add a data relation to be able to get child rows.

http://msdn.microsoft.com/library/d...tml/frlrfsystemdatadatarelationclasstopic.asp

Ken
-----------------------
Dear Group,

I'm having problems retrieving the child rows of a parent row. The parent
table is Users and the child table is Addresses. I used the Schema to
create a DataRelation between the Primary Key of the parent table and a Long
Integer field of the child table. I allowed default (which defaults to
Cascade) in the relationship. The relationship is titled "drlnUserAddress".
I always get a return of 0 child rows and there are four rows in the child
table which match the parent row (0).

If anyone sees an error in my code, please let me know. Or if you can think
of things to check whereby I may be making an error. Below is the code
segment. Thank you very much!



==================== CODE SEGMENT========================

Dim UserCount As Integer
Dim ChildRows() As DataRow
Dim ChildRow As Integer
Dim ChildCount As Integer

'Change Select command - I select a particular username
Me.OleDbSelectCommand1.CommandText = "SELECT Notes, [Password], UserID,
Username, Verify FROM Users WHERE (Username = '" &
Trim(TextBox1.Text.ToString) & "')"

Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
Me.OleDbDataAdapter1.Fill(DsLoginB1)
Me.OleDbDataAdapter2.Fill(DsLoginB1)

UserCount = DsLoginB1.Users.Rows.Count
Label5.Text = UserCount.ToString

'Use just the first row of the parent results "0"
ChildRows = DsLoginB1.Users(0).GetChildRows("drlnUserAddress")

ChildCount = ChildRows.Length
Label4.Text = ChildCount.ToString

'Place the childRows field("City") in the dropdown Box
For ChildRow = 0 To ChildRows.Length - 1
DropDownList1.Items.Add(ChildRows(ChildRow).Item("City"))
Next

========== END CODE SEGMENT ===================

Thank you,

glenn
 

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

Top