kumarsundaram
asked on
Navigating data in related tables
Hello All,
I am in the process of learning VB.NET and ADO.NET. I am working on an application that requires relationship between tables.
Now I have a relationship setup like this:
tableRelation = New DataRelation("relation", dsTest.Tables("clients").C olumns("cl ientID"), dsTest.Tables("tasks").Col umns("clie ntID"))
And, I added that relationship to my dataset as follows:
dsTest.Relations.Add(table Relation)
Now, I have a list box and a text box. The idea is to display the clientName (from my clients table as you can see in the relationship above) on my listbox. And, when the user selects a clientname from the list box I want the client's phone number to be displayed on the text box (example setup I have now for testing purposes).
So, I populate the listbox like this:
For Each rowParent In dsTest.Tables("clients").R ows
ListBox1.Items.Add(rowPare nt("client Name"))
Next
And that's working beautifully and displays the all the client names in the list box.
NOW, THIS IS WHERE MY PROBLEM BEGINS:-)
The code that I have currently is as follows in the listbox1_selectedIndexChan ged control:
Private Sub ListBox1_SelectedIndexChan ged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChan ged
Dim task As String
Dim selectedClient As DataRow
Dim selectedColumn As DataColumn
Dim drArray As DataRow()
drArray = rowParent.GetChildRows("ta bleRelatio n")
For Each selectedClient In drArray
For Each selectedColumn In selectedClient.Table.Colum ns
task = selectedClient("taskName")
Next
Label1.Text = task
Next
End Sub
Now, Of course this doesn't work:-( I don't know how else to do it. Could you please help me pointing in the right direction on how I can accomplish displaying related data in listbox and a textbox as I described in the beginning.... If my code is entirely wrong can you provide me some sample code to get started??? Thanks a lot in advance.
I am in the process of learning VB.NET and ADO.NET. I am working on an application that requires relationship between tables.
Now I have a relationship setup like this:
tableRelation = New DataRelation("relation", dsTest.Tables("clients").C
And, I added that relationship to my dataset as follows:
dsTest.Relations.Add(table
Now, I have a list box and a text box. The idea is to display the clientName (from my clients table as you can see in the relationship above) on my listbox. And, when the user selects a clientname from the list box I want the client's phone number to be displayed on the text box (example setup I have now for testing purposes).
So, I populate the listbox like this:
For Each rowParent In dsTest.Tables("clients").R
ListBox1.Items.Add(rowPare
Next
And that's working beautifully and displays the all the client names in the list box.
NOW, THIS IS WHERE MY PROBLEM BEGINS:-)
The code that I have currently is as follows in the listbox1_selectedIndexChan
Private Sub ListBox1_SelectedIndexChan
Dim task As String
Dim selectedClient As DataRow
Dim selectedColumn As DataColumn
Dim drArray As DataRow()
drArray = rowParent.GetChildRows("ta
For Each selectedClient In drArray
For Each selectedColumn In selectedClient.Table.Colum
task = selectedClient("taskName")
Next
Label1.Text = task
Next
End Sub
Now, Of course this doesn't work:-( I don't know how else to do it. Could you please help me pointing in the right direction on how I can accomplish displaying related data in listbox and a textbox as I described in the beginning.... If my code is entirely wrong can you provide me some sample code to get started??? Thanks a lot in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
have you set a breakpoint in the code, and then stepped through the code, to see what is happening, when?
AW
AW
ASKER
Thanks for pointing out the relationship name... It *kind of* works now but not quite what I wanted it to...
When I select a name (clientname in this case) in the listbox, It does display something on the label. But, the label isn't getting updated everytime I select a different client name on the list box. I tried moving the line "label1.text = task" to different areas of the nested loop. It doesn't do the trick.
I feel like my code is missing something for it to update the text in the label everytime I choose a different name in the listbox(displaying the task name for selected client name)
Any thoughts???
Thanks