469,160 Members | 1,990 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,160 developers. It's quick & easy.

multi table dataset and navigating between records

Hi all,

I've once asked about that topic. but didn't get an answer.

I have a dataset based on 4 tables, which have relation between them.
The main table presented to the user on textboxes placed on the form, and
the rest of the tables presented on textboxes placed on tabpages (tabpage
for each table).
Here is the code I use:
Code:
Function CraeteDataset(ByVal strConnection As String, ByVal stWhereClause As
String) As DataSet
Dim stMasterKeyColumns() As String = {"compid", "customer_id"}
Dim stDetailKeyColumns() As String = {"compid", "entity_id"}
Try
Dim dsData As New DataSet
Dim stWhereClauseAdd As String
Dim drDataRow As DataRow
dsData = clsDBGEN.FillDataSet(strConnection, "table1", _
"select * from table1", False, "table1", dsData)
dsData = clsDBGEN.FillDataSet(strConnection, "table2", _
"select * from table2", False, "table2", dsData)
dsData = clsDBGEN.FillDataSet(strConnection, "table3", _
"select * from table3", False, "table3", dsData)
dsData = clsDBGEN.FillDataSet(strConnection, "table4", _
"select * from table4", False, "table4", dsData)
dsData = clsDBGEN.CreateRelationship("table1", "table2", _
stMasterKeyColumns, stDetailKeyColumns, "table1table2", dsData)
dsData = clsDBGEN.CreateRelationship("table1", "table3", _
stMasterKeyColumns, stDetailKeyColumns, "table1table3", dsData)
dsData = clsDBGEN.CreateRelationship("table1", "table4", _
stMasterKeyColumns, stDetailKeyColumns, "table1table4", dsData)
Return dsData
Catch ex As Exception
HandleExceptions(ex)
End Try
End Function

Private Sub FillHeader(ByRef dsDataSet As DataSet)
Try
stDataSetTable = dsDataSet.Tables.Item("table1").ToString
txtId.DataBindings.Add(New Binding("text", dsDataSet,
stDataSetTable & ".id"))
txtName.DataBindings.Add(New Binding("text", dsDataSet,
stDataSetTable & ".name"))
Catch ex As Exception
HandleExceptions(ex)
MsgBox("Query caused no record to be retrieved",
MsgBoxStyle.Information)
End Try
End Sub

Private Sub FillLines(ByRef dsDataSet As DataSet)
Try
For Each drDataRow As DataRow In dsDataSet.Tables("table2").Rows
If drDataRow("compid") = dCompid And drDataRow("entity_id") = _
txtId.Text Then
txtStreet.DataBindings.Add("text", dsDataSet,
"table1.table1table2.street")
txtStrNo.DataBindings.Add("text", dsDataSet,
"table1.table1table2.street_no")
End If
Next
For Each drDataRow As DataRow In dsDataSet.Tables("table3").Rows
If drDataRow("compid") = dCompid And drDataRow("entity_id") = _
txtId.Text Then
txtShpStreet.DataBindings.Add("text", dsDataSet,
"table1.table1table3.street")
txtShpStrNo.DataBindings.Add("text", dsDataSet,
"table1.table1table3.street_no")
End If
Next
txt1.DataBindings.Add("text", dsDataSet,
"table1.table1table4.field1")
txt2.DataBindings.Add("text", dsDataSet,
"table1.table1table4.field2")
Catch ex As Exception
HandleExceptions(ex)
MsgBox("Query caused no record to be retrieved",
MsgBoxStyle.Information)
End Try
End Sub

When I query the dataset, each filed show the correct data. The same happens
when I navigate between records
When I change data in the main form, and then navigate between records, the
changes are saved to the dataset. (as expected)
When I change data in one of the tabpages and then navigate between records,
the changes not save to the dataset.
What do I miss here?

Here is the code for navigating next for example:

Code:
Sub MoveNext(ByVal dsDataSet As DataSet, ByVal stDataSetTable As String)
Try
bdRecordNavigator = BindingContext(dsDataSet, stDataSetTable)
bdRecordNavigator.EndCurrentEdit()
bdRecordNavigator.Position += 1
Catch ex As Exception
HandleExceptions(ex)
End Try
End Sub

Thanks for your help
Mar 25 '07 #1
0 1245

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Graham Blandford | last post: by
reply views Thread by Gareth Stretch | last post: by
5 posts views Thread by Robert Brown | last post: by
4 posts views Thread by RG | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.