3
Answers

Load the second combobox

Israel

Israel

9y
588
1
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)