S
steve
Hello,
I am a bit perplexed about a simple matter and was wondering if anybody
could help me.
I also apologize if I am out of topic for the vb group.
What I want to do is the following:
Be able to display specific records from a database (Access) which can be
chosen by various fields. I want to allow the user to choose from a couple
of fields (name, id, etc) which obviously have to be synchronized. I also
want to use the *same* combos and textfields after switching tables in the
database.
As a practice example i used the Northwind db and created two combos and one
textbox. On top there are two radio buttons that (should) allow the user to
switch datasets. Obviously, you select the dataset -> populate the boxes ->
the user can select various records through *either of the comboboxes* (name
or id) -> various textboxes (addres, phone etc) get populated .
At any time you click on a radio button and switch from e.g. customers to
products table, and do the same with similar fields.
Very straightforward but ... i managed to raise an exception!
After a LOT of experimenting, my latest version works except when trying to
switch between datasets.
- Neither of the radiobuttons is checked by default and no DisplayMembers or
DataSources are visually set.
- after starting the program whichever radio is selected everything works as
expected. Once you try to switch, you get an exception.
Below is the code for the CheckedChanged event of the radio buttons.
Incidentally, i use "beginning Visual Basic .NET Databases" by Wrox. Are
there any suggestions for online resources reading about these things? What
perplexes me is that they suggest to have one dataadapter per table.
Although it can handle more it's not a good idea. So, if in a form you need
data from 7 tables you have to have 7 adapters ?.. how about datasets? one
per dataadapter also?....
Thanx in advance for any help guidance and my apologies for writing so much.
- steve
------------------------------------------------------
Private Sub Choix()
Dim records As Integer
If rdbCustomer.Checked = True Then
DataSet11.Clear()
DataSet21.Clear()
DataAdapter1.Fill(DataSet11)
cmb1.DataSource = DataSet11
cmb1.DisplayMember = "Customers.CustomerID"
cmb2.DataSource = DataSet11
cmb2.DisplayMember = "Customers.name"
txtBox1.DataBindings.Add("text", DataSet11, "customers.city")
Else
DataSet11.Clear()
DataSet21.Clear()
DataAdapter2.Fill(DataSet21)
cmb1.DataSource = DataSet21
cmb1.DisplayMember = "Products.pid"
cmb2.DataSource = DataSet21
cmb2.DisplayMember = "Products.price"
txtBox1.DataBindings.Add("text", DataSet21, "Products.price")
End If
End Sub
I am a bit perplexed about a simple matter and was wondering if anybody
could help me.
I also apologize if I am out of topic for the vb group.
What I want to do is the following:
Be able to display specific records from a database (Access) which can be
chosen by various fields. I want to allow the user to choose from a couple
of fields (name, id, etc) which obviously have to be synchronized. I also
want to use the *same* combos and textfields after switching tables in the
database.
As a practice example i used the Northwind db and created two combos and one
textbox. On top there are two radio buttons that (should) allow the user to
switch datasets. Obviously, you select the dataset -> populate the boxes ->
the user can select various records through *either of the comboboxes* (name
or id) -> various textboxes (addres, phone etc) get populated .
At any time you click on a radio button and switch from e.g. customers to
products table, and do the same with similar fields.
Very straightforward but ... i managed to raise an exception!
After a LOT of experimenting, my latest version works except when trying to
switch between datasets.
- Neither of the radiobuttons is checked by default and no DisplayMembers or
DataSources are visually set.
- after starting the program whichever radio is selected everything works as
expected. Once you try to switch, you get an exception.
Below is the code for the CheckedChanged event of the radio buttons.
Incidentally, i use "beginning Visual Basic .NET Databases" by Wrox. Are
there any suggestions for online resources reading about these things? What
perplexes me is that they suggest to have one dataadapter per table.
Although it can handle more it's not a good idea. So, if in a form you need
data from 7 tables you have to have 7 adapters ?.. how about datasets? one
per dataadapter also?....
Thanx in advance for any help guidance and my apologies for writing so much.
- steve
------------------------------------------------------
Private Sub Choix()
Dim records As Integer
If rdbCustomer.Checked = True Then
DataSet11.Clear()
DataSet21.Clear()
DataAdapter1.Fill(DataSet11)
cmb1.DataSource = DataSet11
cmb1.DisplayMember = "Customers.CustomerID"
cmb2.DataSource = DataSet11
cmb2.DisplayMember = "Customers.name"
txtBox1.DataBindings.Add("text", DataSet11, "customers.city")
Else
DataSet11.Clear()
DataSet21.Clear()
DataAdapter2.Fill(DataSet21)
cmb1.DataSource = DataSet21
cmb1.DisplayMember = "Products.pid"
cmb2.DataSource = DataSet21
cmb2.DisplayMember = "Products.price"
txtBox1.DataBindings.Add("text", DataSet21, "Products.price")
End If
End Sub