PC Review


Reply
Thread Tools Rate Thread

Comboboxes and queries

 
 
Nicolae Fieraru
Guest
Posts: n/a
 
      31st Jan 2005
Hi All,

I have a database with two tables. One is called tblMainCategory and the
other one tblCategory. The tblMainCategories has fields Index1 and
MainCategory.
The tblCategory has Index2, MainCategoryId and Category.

I have a form with two comboboxes. I want to populate the first combobox
with the strings from MainCategory field. Then, when I select one of the
values from the dropdown, I want to populate the second combobox only with
those records.

I decided to try first using datareader. I can populate the first combobox.
But then I realised I need the value of the Index1 from tblMainCategories,
in order to be able to query the elements for the second combobox. I suppose
I could use another query, an ExecuteScalar to retrieve the corresponding
Index1 for MainCategory which was chosen from the dropdown.

Is there a simpler way than this one? For example I can see that a combobox
has a ValueMember property and a DisplayMember property. Is that a list or
what? If it is a list, then I can add the Index1 from the query. I tried
with ComboBox->ValueMember->Items->Add, but it doesn't work...


Regards,
Nicolae


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      31st Jan 2005
Nicolae,

As soon as you need two items than the datareader becomes not the best way
to fill a combobox.
You can do it be creating a class and from that objects to put in the items,
however very insufficient (when you need more than 2 items this will be the
way to go).

The datatable is the way to go with 2 items. It is this in code in vb style
(which last is only important for the first 2 rows) xxx is for OleDB or for
SQLClient or for OracleClient

\\\
dim dt as new datatable
dim da as xxxDataAdapter as new xxxDataAdapter(SqlSelectString,conn)
da.fill(dt)
combobox1.DataSource = dt
combobox1.DisplayMember = "mydisplaymember"
combobox1.ValueMember = "myValuemember"
///

That is all,

I hope this helps

Cor


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Switchboard queries with ComboBoxes Spike Microsoft Access 1 30th Oct 2008 03:18 PM
comboboxes =?Utf-8?B?WmFhaGly?= Microsoft Excel Programming 1 13th Nov 2006 02:18 PM
ComboBoxes ? tiger Microsoft Access 1 3rd Mar 2006 07:49 AM
Queries using parameter queries, assigning values to for params in called query, is it possible? =?Utf-8?B?RnJhbmsgTS4=?= Microsoft Access Queries 1 13th Mar 2004 07:06 AM
Comboboxes Steven Smith Microsoft VB .NET 3 19th Nov 2003 10:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 PM.