Start New Discussion within our Software Development Community

I am trying to filter a 2nd Combobox based on the selected value of the 1st Comboxbox. For example, when the user choses "BMW" from the cbxmanufacturer control, I need the cbxModel control to display all models associated to "BMW". I am almost there but I get an error "Cannot find Column[System.Data.DataRowView", please help!

My code is

private void NewVehicleDetails_Load(object sender, EventArgs e)
        {

            connection.ConnectionString = "";

            command.CommandText = "SELECT * FROM Vehicle_Model; " +
                                  "SELECT DISTINCT ManufacturerName FROM Vehicle_Manufacturer;";
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            adapter.SelectCommand.Connection = connection;
            adapter.Fill(dSet);
                        
            cbxManufacturer.DisplayMember = "ManufacturerName";
            cbxManufacturer.ValueMember = "ManufacturerID";
            cbxManufacturer.DataSource = dSet.Tables[1];

            cbxModel.DisplayMember = "ModelName";
            cbxModel.ValueMember = "ModelID";
            cbxModel.DataSource = dSet.Tables[0];
                       
        }
        
        private void cbxManufacturer_SelectionChangeCommitted(object sender, EventArgs e)
        {
            
            string comb1 = ((System.Windows.Forms.ListControl)(cbxManufacturer)).SelectedValue.ToString();
            string expr = "ManufacturerID = " + comb1;
            DataRow[] dRows = dSet.Tables[0].Select(expr); // Errors here

            for (int i = 0; i < dRows.Length; i++)
            {
                cbxModel.Items.Add(dRows[i].ItemArray[1].ToString());
            }
            
        }

If you run the query for "ManufacturerID = " + comb1 in SQL Server Management Studio, can you get the result successfully?

This article has been dead for over six months. Start a new discussion instead.