HELP: Control dataset synchronization

S

steve

Hello,
Can anybosy guide me to the right direction to synchronize two controls from two different tables?

Both tables have been filled to the dataset by two separate adapters, the controls have been bound to different fields in the two tables and everything is nice, except that the controls are NOT synchronized.
They are independent. i.e. if you scroll on one list the other doesnt change accoringly and vice versa.

The two tables have (in the original database) a parent-child relationship with a foreign key. Do the two rtables have to be of equal size ?????

The important part of the code is below,
Am i missing something?

Thanx in advance!
steve


---------------------------------------------------------------------------------------------------------------------------------

Dim strDBConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& "C:\RAFALE\Beta\BD\Rafalebd.mdb"

Dim DBConnection As OleDbConnection = New OleDbConnection(strDBConnection)
DBConnection.Open()

''''' First string and adapter
Dim strSelectQA1 As String = "SELECT * FROM tblInfoQA "
'SQL Data Adapter !!!
Dim DBAdapterQA As OleDbDataAdapter = New OleDbDataAdapter(strSelectQA1, DBConnection)
Dim DS As New DataSet
DS.EnforceConstraints = False
DBAdapterQA.Fill(DS, "tblInfoQA")

''''' Second string and adapter
Dim strSelectQA2 As String = "SELECT * FROM tblQAHor"
DBAdapterQA = New OleDbDataAdapter(strSelectQA2, DBConnection)
DBAdapterQA.Fill(DS, "tblQAHor")

DS.EnforceConstraints = True

DBConnection.Close()

'Relation
DS.Relations.Add("experiment2", _
DS.Tables("tblInfoQA").Columns("MENVid"), _
DS.Tables("tblQAHor").Columns("MENVid"))

'********** CONTROLS ***********
cmb1.DataSource = DS
cmb1.DisplayMember = "tblInfoQA.MENVid"

cmb2.DataSource = DS
cmb2.DisplayMember = "tblInfoQA.O3"

lbl1.DataBindings.Clear()
lbl1.DataBindings.Add("text", DS, "tblQAHor.NO")
'*********************
------------------------------------------------------------------------------------------------------------------------------
 
C

Cor Ligthert

Steve,

This is the thirth time today I sent this sample what I made today, can you tell me if it helps you because it is brand new.

Cor

\\\ Needs a form with two datagrids, a button and a label
'The first click on the button shows one datagrid
'The second click shows the same info with two datagrid
'To make it nice a lot of other code is needed by instance datagridtablestyles
'and columnstyles
Private Ds As New DataSet
Private dtCountries As DataTable
Private dtVBLTRegulars As DataTable
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
CreateTables()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Static pushed As Integer = 1
Select Case pushed
Case 1
Label1.Text = "Relation One Datagrid"
Dim drel As New DataRelation _
("Regulars", Ds.Tables("Countries").Columns("Country"), _
Ds.Tables("Persons").Columns("Country"))
Ds.Relations.Add(drel)
DataGrid1.DataSource = dtCountries
DataGrid1.Expand(-1)
Case 2
Ds.Relations.RemoveAt(0)
Label1.Text = "Relation two Datatgrids"
Dim drel As New DataRelation _
("Regulars", Ds.Tables("Countries").Columns("Country"), _
Ds.Tables("Persons").Columns("Country"))
Ds.Relations.Add(drel)
DataGrid1.SetDataBinding(Ds, "Countries")
DataGrid2.SetDataBinding(Ds, "Countries.Regulars")
End Select
pushed += 1
End Sub
'This is only needed to show the sample
Private Sub CreateTables()
dtVBLTRegulars = New DataTable("Persons")
dtVBLTRegulars.Columns.Add("Id")
dtVBLTRegulars.Columns.Add("Name")
dtVBLTRegulars.Columns.Add("Country")
For i As Integer = 0 To 7
Dim dr As DataRow = dtVBLTRegulars.NewRow
dr(0) = i.ToString
dtVBLTRegulars.Rows.Add(dr)
Next
dtVBLTRegulars.Rows(0)(1) = "Herfried K. Wagner"
dtVBLTRegulars.Rows(1)(1) = "Ken Tucker"
dtVBLTRegulars.Rows(2)(1) = "CJ Taylor"
dtVBLTRegulars.Rows(3)(1) = "Jay B Harlow"
dtVBLTRegulars.Rows(4)(1) = "Terry Burns"
dtVBLTRegulars.Rows(5)(1) = "Tom Shelton"
dtVBLTRegulars.Rows(6)(1) = "Cor Ligthert"
dtVBLTRegulars.Rows(0)(2) = "EU"
dtVBLTRegulars.Rows(1)(2) = "US"
dtVBLTRegulars.Rows(2)(2) = "US"
dtVBLTRegulars.Rows(3)(2) = "US"
dtVBLTRegulars.Rows(4)(2) = "EU"
dtVBLTRegulars.Rows(5)(2) = "US"
dtVBLTRegulars.Rows(6)(2) = "EU"
dtCountries = New DataTable("Countries")
dtCountries.Columns.Add("Id")
dtCountries.Columns.Add("Country")
For i As Integer = 0 To 1
Dim dr As DataRow = dtCountries.NewRow
dr(0) = i.ToString
dtCountries.Rows.Add(dr)
Next
dtCountries.Rows(0)(1) = "EU"
dtCountries.Rows(1)(1) = "US"
Ds.Tables.Add(dtVBLTRegulars)
Ds.Tables.Add(dtCountries)
End Sub
///
 
O

One Handed Man \( OHM - Terry Burns \)

Nice one, I made your famous list

;-D

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


Steve,

This is the thirth time today I sent this sample what I made today, can you tell me if it helps you because it is brand new.

Cor

\\\ Needs a form with two datagrids, a button and a label
'The first click on the button shows one datagrid
'The second click shows the same info with two datagrid
'To make it nice a lot of other code is needed by instance datagridtablestyles
'and columnstyles
Private Ds As New DataSet
Private dtCountries As DataTable
Private dtVBLTRegulars As DataTable
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
CreateTables()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Static pushed As Integer = 1
Select Case pushed
Case 1
Label1.Text = "Relation One Datagrid"
Dim drel As New DataRelation _
("Regulars", Ds.Tables("Countries").Columns("Country"), _
Ds.Tables("Persons").Columns("Country"))
Ds.Relations.Add(drel)
DataGrid1.DataSource = dtCountries
DataGrid1.Expand(-1)
Case 2
Ds.Relations.RemoveAt(0)
Label1.Text = "Relation two Datatgrids"
Dim drel As New DataRelation _
("Regulars", Ds.Tables("Countries").Columns("Country"), _
Ds.Tables("Persons").Columns("Country"))
Ds.Relations.Add(drel)
DataGrid1.SetDataBinding(Ds, "Countries")
DataGrid2.SetDataBinding(Ds, "Countries.Regulars")
End Select
pushed += 1
End Sub
'This is only needed to show the sample
Private Sub CreateTables()
dtVBLTRegulars = New DataTable("Persons")
dtVBLTRegulars.Columns.Add("Id")
dtVBLTRegulars.Columns.Add("Name")
dtVBLTRegulars.Columns.Add("Country")
For i As Integer = 0 To 7
Dim dr As DataRow = dtVBLTRegulars.NewRow
dr(0) = i.ToString
dtVBLTRegulars.Rows.Add(dr)
Next
dtVBLTRegulars.Rows(0)(1) = "Herfried K. Wagner"
dtVBLTRegulars.Rows(1)(1) = "Ken Tucker"
dtVBLTRegulars.Rows(2)(1) = "CJ Taylor"
dtVBLTRegulars.Rows(3)(1) = "Jay B Harlow"
dtVBLTRegulars.Rows(4)(1) = "Terry Burns"
dtVBLTRegulars.Rows(5)(1) = "Tom Shelton"
dtVBLTRegulars.Rows(6)(1) = "Cor Ligthert"
dtVBLTRegulars.Rows(0)(2) = "EU"
dtVBLTRegulars.Rows(1)(2) = "US"
dtVBLTRegulars.Rows(2)(2) = "US"
dtVBLTRegulars.Rows(3)(2) = "US"
dtVBLTRegulars.Rows(4)(2) = "EU"
dtVBLTRegulars.Rows(5)(2) = "US"
dtVBLTRegulars.Rows(6)(2) = "EU"
dtCountries = New DataTable("Countries")
dtCountries.Columns.Add("Id")
dtCountries.Columns.Add("Country")
For i As Integer = 0 To 1
Dim dr As DataRow = dtCountries.NewRow
dr(0) = i.ToString
dtCountries.Rows.Add(dr)
Next
dtCountries.Rows(0)(1) = "EU"
dtCountries.Rows(1)(1) = "US"
Ds.Tables.Add(dtVBLTRegulars)
Ds.Tables.Add(dtCountries)
End Sub
///
 

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