Israel

Israel

  • NA
  • 1.3k
  • 204.1k

Load the second combobox

Nov 24 2014 4:37 AM
Hi!

I have a combobox with three items:
Toyota
Kia
Hyndai

Then I have a small table with two columns (Marks and Models):

Marks  | Modelos
Toyota: Camry

Toyota: Celica
Toyota: Corolla
Kia: Optima
Kia: Picanto
Kia: Sportage
Hyundai: Accent
Hyundai: Azera
Hyundai: Elantra

When I select one mark. What happening? I found in the combobox model the table's name repeted in that combobox:

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\rentacar\rentacar\\app_data\rentacar.mdb;Persist Security Info=False";
            OleDbConnection sqlCon = new OleDbConnection(connectionString);
            sqlCon.Open();
            string commandString = "select * from carsconfig where cars ='" + cbxMarkConfig.Text + "'";
            OleDbCommand sqlCmd = new OleDbCommand(commandString, sqlCon);
            OleDbDataReader read = sqlCmd.ExecuteReader();

            if (read.HasRows)
            {
                while (read.Read())
                {
                    cbxModelsConfig.Items.Add("models"); // it will show the code
                    
                }
            }
            else
            {
                MessageBox.Show("A record with a code of " + cbxMarkConfig.Text + " was not found");
            }

        }
    }

Answers (3)