473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

combo box and database

I am new to the whole c# thing, I now how to get data from a db into a combo
box. My question is: should I have one table for 5 combo box or have 5 tables
for 5 combo box?
Aug 15 '08 #1
2 2004
On Aug 15, 10:42*pm, freddy <fre...@discussions.microsoft.comwrote:
I am new to the whole c# thing, I now how to get data from a db into a combo
box. My question is: should I have one table for 5 combo box or have 5 tables
for 5 combo box?
You shouldn't be thinking about the combo boxes when you design your
database schema, you should be thinking about the nature of the data
itself. Short of that, there's little advice that can be offered to
you here. But perhaps it will help if I tell that you can bind several
comboboxes to data retrieved from the same table.
Aug 15 '08 #2
The method I use is to create one C# dataset that contains a table for each
combobox. So 1 dataset and 5 tables. Create a database query for each table
that returns a display column and a 'key' column for each comobox list.

I basically repeat the following code 5 times. One for each combobox. (I'm
not a fan of direct binding.)

//' -- "Use Code" ComboBox --

sbSql.Remove(0, sbSql.Length);
sbSql.Append("SELECT use_code, use_code + ' - ' + desc as description ");
sbSql.Append("FROM use_code ");
sbSql.Append("WHERE table_name = 'use' ");

sTableName = "use_codes";

mDs = QueryDatabase(sbSql.ToString(), mDs, sTableName, sCallingMethod,
this.m_ReturnStatus);

try
{
DataView oDv = new DataView(mDs.Tables[sTableName], "", "description",
DataViewRowState.CurrentRows);

this.cmbx_From_UseCode.DataSource = oDv;
this.cmbx_From_UseCode.DisplayMember = "description".Trim();
this.cmbx_From_UseCode.ValueMember = "use_code";
this.cmbx_From_UseCode.SelectedIndex = 0;
}
catch
{
#region "failed to load Use Code ComboBox)"

StringBuilder sbMsg = new StringBuilder();
sbMsg.Length = 0;
sbMsg.Append("\n");
sbMsg.Append(sCallingMethod);
sbMsg.Append("\n");
sbMsg.Append("FAILED =to Load Use Code ComboBox.\n");
sbMsg.Append("\n");
sbMsg.Append("This is a run time error and should not normally occur.\n");
sbMsg.Append("\n");
sbMsg.Append("Please copy this message and send it to the staff member\n");
sbMsg.Append("responsible for maintiaing this application.\n");
sbMsg.Append("\n");
sbMsg.Append("Thank you.\n");
sbMsg.Append("\n");
MessageBox.Show(sbMsg.ToString().Trim(), "ComboBox initial load failure:",
MessageBoxButtons.OK, MessageBoxIcon.Error);

#endregion

}

"Pavel Minaev" <in****@gmail.comwrote in message
news:e7**********************************@34g2000h sh.googlegroups.com...
On Aug 15, 10:42 pm, freddy <fre...@discussions.microsoft.comwrote:
I am new to the whole c# thing, I now how to get data from a db into a
combo
box. My question is: should I have one table for 5 combo box or have 5
tables
for 5 combo box?
You shouldn't be thinking about the combo boxes when you design your
database schema, you should be thinking about the nature of the data
itself. Short of that, there's little advice that can be offered to
you here. But perhaps it will help if I tell that you can bind several
comboboxes to data retrieved from the same table.
Aug 18 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mal | last post by:
Sorry for repost - system added to another subject for some reason Have tried numerous ideas from the group to solve this one. It is such a simple example that it should be straightforward ! I...
2
by: Jeremy Dillinger | last post by:
I have a program setup to pull data from a database. My database table has things such as (category, Item, price, etc.) In my program I want to have multiple list boxes that will have a pull down...
2
by: TS | last post by:
Hi all, From my windows form, I opened a connection to a SQL database. Now I need to generate a combo box from a SELECT statement pointing to the last name column in the SQL tables. I am stuck...
3
by: Frustrated Developer via DotNetMonster.com | last post by:
I have posted a couple times on here already and found the user community to be very helpful. I took on a project before I realized how difficult a time I'm having working with a database....
5
by: Shreekant Patel | last post by:
Hello, I am new to the advanced level of access, and I have quite a few changes to make to an existing database. The current database's main form needs to have additional check boxes added to...
0
by: Tom | last post by:
I have some very strange issues with combo boxes on a tab control. Here's the scenario: I have a Windows Forms form that has a tab control on it, with two (2) tabs. Tab 2 happens to have a number...
2
by: 5070707 | last post by:
Hi all this question might be more SQL oriented or at least database structure... i created a table in my SQL which contains 2 columns: 1. state 2. country the way i input the data is: State...
4
by: Dave | last post by:
I wasn't sure how to search for previous posts about this, it felt real specific. Ok so here's the database & problem: I have 4 combo boxes: cboServer, cboPolicy, cboDB, and cboApplication. ...
2
by: biganthony via AccessMonster.com | last post by:
Hi, I decided to install Office 2003 Service Pack 3 on my home computer to test (in full knowledge that there may be some issues with it). After installation, I have noticed that with a small...
0
by: Del | last post by:
Hello and thanks for any and all assistance! I have a database that is used by several users on several different machines. The backend database is housed on a file server. Each user has a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.