HELP! Dataset - synchronised controls

S

steve

Hello,
I have been trying to populate 2 or more controls from two *different*
(related) tables for the last week without success.
My latest try is: 2 simple SELECT statements in 2 adapters that populate the
*same* dataset and then i define a relation among the two tables.
SIMPLE!!!!!!!
Everything works fine but the controls from different tables are NOT
synchronised.

Am I doing something wrong or this is the wrong way altogether to attack
this problem?

I *also* tried to create a "complete" SELECT statement and pass the result
in the dataset with no success either.

Can anyone help? I know its very easy but i cant see what is wrong with my
code.

(Obviously i left out connection string etc. since everything else is
working)
And I am NOT asking for DataGrids!!!!!! this is easy. it worked. and i could
see where every column was coming from.
I am interested in labels, textboxes and droplists.

Thanx in advance
-steve

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

Dim strSelect1 As String = " SELECT * FROM tblCustomers"
Dim strSelect2 As String = " SELECT * FROM tblOrders "
Dim DS As New DataSet

'SQL Data Adapter
Dim DBAdapter1 As OleDbDataAdapter = New OleDbDataAdapter(strSelect1,
DBConnection)
DBAdapter1.Fill(DS, "tblCustomers")

Dim DBAdapter2 As OleDbDataAdapter = New OleDbDataAdapter(strSelect2,
DBConnection)
DBAdapter2.Fill(DS, "tblOrders")

DS.Relations.Add("CustomerOrders", _
DS.Tables("tblCustomers").Columns("CustomerID"), _
DS.Tables("tblOrders").Columns("CustomerID"))


'****** populate controls ***************
cmb1.DataSource = DS
cmb1.DisplayMember = "tblCustomers.CustomerID"

cmb2.DataSource = DS
cmb2.DisplayMember = "tblOrders.OrderID"

lbl1.DataBindings.Clear()
lbl1.DataBindings.Add("text", DS, "tblOrders.Date")
'*********************
 
K

Ken Tucker [MVP]

Hi,

Create a dataview for each table. Bind the controls to the
dataviews. When you change records filter the dataview to only show the
desired records.

http://msdn.microsoft.com/library/d...l/vbtskcodeexamplefilteringdataindataview.asp


Ken
--------------------
Hello,
I have been trying to populate 2 or more controls from two *different*
(related) tables for the last week without success.
My latest try is: 2 simple SELECT statements in 2 adapters that populate the
*same* dataset and then i define a relation among the two tables.
SIMPLE!!!!!!!
Everything works fine but the controls from different tables are NOT
synchronised.

Am I doing something wrong or this is the wrong way altogether to attack
this problem?

I *also* tried to create a "complete" SELECT statement and pass the result
in the dataset with no success either.

Can anyone help? I know its very easy but i cant see what is wrong with my
code.

(Obviously i left out connection string etc. since everything else is
working)
And I am NOT asking for DataGrids!!!!!! this is easy. it worked. and i could
see where every column was coming from.
I am interested in labels, textboxes and droplists.

Thanx in advance
-steve

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

Dim strSelect1 As String = " SELECT * FROM tblCustomers"
Dim strSelect2 As String = " SELECT * FROM tblOrders "
Dim DS As New DataSet

'SQL Data Adapter
Dim DBAdapter1 As OleDbDataAdapter = New OleDbDataAdapter(strSelect1,
DBConnection)
DBAdapter1.Fill(DS, "tblCustomers")

Dim DBAdapter2 As OleDbDataAdapter = New OleDbDataAdapter(strSelect2,
DBConnection)
DBAdapter2.Fill(DS, "tblOrders")

DS.Relations.Add("CustomerOrders", _
DS.Tables("tblCustomers").Columns("CustomerID"), _
DS.Tables("tblOrders").Columns("CustomerID"))


'****** populate controls ***************
cmb1.DataSource = DS
cmb1.DisplayMember = "tblCustomers.CustomerID"

cmb2.DataSource = DS
cmb2.DisplayMember = "tblOrders.OrderID"

lbl1.DataBindings.Clear()
lbl1.DataBindings.Add("text", DS, "tblOrders.Date")
'*********************
 
S

steve

Thanx Ken,
However, i dont think this would be the answer or at least the *simple*
answer.

Is it really so complicated to just *bind and synchronize* two controls from
two different tables ??????

thanx again!
 
S

steve

An addition:

when i change the first connection string to:
SELECT tblCustomers.*, tblOrders.* FROM (tblCustomersINNER JOIN tblOrders ON tblOrders.CustomerID = tblCustomers.CustomerID)

then things work *except* the first combobox: tblCustomers.CustomerID !!!

Actually as i read on the Net if you do something like this then the resulting table is by fefault called by the first table's name: tblCustomers in our case. This is why i can access tblCustomers.OrderID or something, that doesnt belong to that table originally.
 

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