combo box and database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?ZnJlZGR5?=

    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?
  • Pavel Minaev

    #2
    Re: combo box and database

    On Aug 15, 10:42 pm, freddy <fre...@discuss ions.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.

    Comment

    • frostbb

      #3
      Re: combo box and database

      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("S ELECT use_code, use_code + ' - ' + desc as description ");
      sbSql.Append("F ROM use_code ");
      sbSql.Append("W HERE table_name = 'use' ");

      sTableName = "use_codes" ;

      mDs = QueryDatabase(s bSql.ToString() , mDs, sTableName, sCallingMethod,
      this.m_ReturnSt atus);

      try
      {
      DataView oDv = new DataView(mDs.Ta bles[sTableName], "", "descriptio n",
      DataViewRowStat e.CurrentRows);

      this.cmbx_From_ UseCode.DataSou rce = oDv;
      this.cmbx_From_ UseCode.Display Member = "description".T rim();
      this.cmbx_From_ UseCode.ValueMe mber = "use_code";
      this.cmbx_From_ UseCode.Selecte dIndex = 0;
      }
      catch
      {
      #region "failed to load Use Code ComboBox)"

      StringBuilder sbMsg = new StringBuilder() ;
      sbMsg.Length = 0;
      sbMsg.Append("\ n");
      sbMsg.Append(sC allingMethod);
      sbMsg.Append("\ n");
      sbMsg.Append("F AILED =to Load Use Code ComboBox.\n");
      sbMsg.Append("\ n");
      sbMsg.Append("T his is a run time error and should not normally occur.\n");
      sbMsg.Append("\ n");
      sbMsg.Append("P lease copy this message and send it to the staff member\n");
      sbMsg.Append("r esponsible for maintiaing this application.\n" );
      sbMsg.Append("\ n");
      sbMsg.Append("T hank you.\n");
      sbMsg.Append("\ n");
      MessageBox.Show (sbMsg.ToString ().Trim(), "ComboBox initial load failure:",
      MessageBoxButto ns.OK, MessageBoxIcon. Error);

      #endregion

      }



      "Pavel Minaev" <int19h@gmail.c omwrote in message
      news:e7cf1a85-a04a-433a-8500-2b23030d302b@34 g2000hsh.google groups.com...
      On Aug 15, 10:42 pm, freddy <fre...@discuss ions.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.


      Comment

      Working...