combo box and database

F

freddy

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?
 
P

Pavel Minaev

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.
 
F

frostbb

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

}



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.
 

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