Hi,
I was able to do a data relation between parent and child, and using a bindingcontextbase I was able to display in textbox and navigate the records of the parent table. How can I make the datagridview display the child records when the textbox value has changed when I navigate it by not using a SQL command? I've googled every site but I still can't figure out how to do this. Thanks
sample code:
Dim sqlAdapter As SqlClient.SqlDataAdapter = Nothing
sqlAdapter = New SqlClient.SqlDataAdapter()
sqlAdapter.SelectCommand = New SqlCommand("select * from zCT_Contact", sqlCon)
Dim dSet As New DataSet("All Tables")
sqlAdapter.Fill(dSet, "NewTable 1")
sqlAdapter = New SqlClient.SqlDataAdapter()
sqlAdapter.SelectCommand = New SqlCommand("select * from zAD_Address", sqlCon)
sqlAdapter.Fill(dSet, "NewTable 2")
sqlAdapter = New SqlClient.SqlDataAdapter()
sqlAdapter.SelectCommand = New SqlCommand("select * from ar_category", sqlCon)
sqlAdapter.Fill(dSet, "NewTable 3")
TextBox1.DataBindings.Add(New Binding("Text", dSet, "NewTable 1.Name"))
TextBox2.DataBindings.Add(New Binding("Text", dSet, "NewTable 1.Address"))
'create the binding manager for each table
bMgrBase = Me.BindingContext(dSet, "NewTable 1")
bMgrBase1 = Me.BindingContext(dSet, "NewTable 2")
'Using DataRelation object
Dim drMyRelation As New DataRelation("dSet", dSet.Tables("NewTable 1").Columns("ctContactID"), dSet.Tables("NewTable 2").Columns("ctContactID"))
dSet.Relations.Add(drMyRelation)
'Code for navigating, sample only...
Private Sub btnFirstRec_Click(...)
bMgrBase.Position = 0
bMgrBase1.Position = 0
End Sub
Private Sub btnNextRec_Click(...)
If bMgrBase.Position < bMgrBase.Count Then
bMgrBase.Position += 1
End If
If bMgrBase1.Position < bMgrBase1.Count Then
bMgrBase1.Position += 1
End If
End Sub
Thanks for all your help.
I was able to do a data relation between parent and child, and using a bindingcontextbase I was able to display in textbox and navigate the records of the parent table. How can I make the datagridview display the child records when the textbox value has changed when I navigate it by not using a SQL command? I've googled every site but I still can't figure out how to do this. Thanks
sample code:
Dim sqlAdapter As SqlClient.SqlDataAdapter = Nothing
sqlAdapter = New SqlClient.SqlDataAdapter()
sqlAdapter.SelectCommand = New SqlCommand("select * from zCT_Contact", sqlCon)
Dim dSet As New DataSet("All Tables")
sqlAdapter.Fill(dSet, "NewTable 1")
sqlAdapter = New SqlClient.SqlDataAdapter()
sqlAdapter.SelectCommand = New SqlCommand("select * from zAD_Address", sqlCon)
sqlAdapter.Fill(dSet, "NewTable 2")
sqlAdapter = New SqlClient.SqlDataAdapter()
sqlAdapter.SelectCommand = New SqlCommand("select * from ar_category", sqlCon)
sqlAdapter.Fill(dSet, "NewTable 3")
TextBox1.DataBindings.Add(New Binding("Text", dSet, "NewTable 1.Name"))
TextBox2.DataBindings.Add(New Binding("Text", dSet, "NewTable 1.Address"))
'create the binding manager for each table
bMgrBase = Me.BindingContext(dSet, "NewTable 1")
bMgrBase1 = Me.BindingContext(dSet, "NewTable 2")
'Using DataRelation object
Dim drMyRelation As New DataRelation("dSet", dSet.Tables("NewTable 1").Columns("ctContactID"), dSet.Tables("NewTable 2").Columns("ctContactID"))
dSet.Relations.Add(drMyRelation)
'Code for navigating, sample only...
Private Sub btnFirstRec_Click(...)
bMgrBase.Position = 0
bMgrBase1.Position = 0
End Sub
Private Sub btnNextRec_Click(...)
If bMgrBase.Position < bMgrBase.Count Then
bMgrBase.Position += 1
End If
If bMgrBase1.Position < bMgrBase1.Count Then
bMgrBase1.Position += 1
End If
End Sub
Thanks for all your help.
Last edited: