0

I want to fill a combo box depending on another combo box.I tried to find it for 2 days.

I have a database with 3 tables.

  1. ID, BrandName
  2. ID, SerieName, BrandID
  3. ID, ProfileNam, SerieID

My Form is like this.

First combo box fill with Brandname and its working well with the code below.

 private void MarkaYukle()
    {
        string dbBaglantiYolu = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Personal Files\\Otomasyon\\VB\\SmallCNC_V01.00\\database\\database01.mdb";

        try
        {
            using (OleDbConnection baglanti=new OleDbConnection(dbBaglantiYolu))
            {
                baglanti.Open();
                string dataYolu = "SELECT * FROM Markalar";
                OleDbDataAdapter adaptor = new OleDbDataAdapter(dataYolu, baglanti);
                DataSet ds = new DataSet();
                adaptor.Fill(ds);
                comboMarkaSec.DataSource = ds.Tables[0];
                comboMarkaSec.DisplayMember = "MarkaAdi";
                comboMarkaSec.ValueMember = "ID";

            }
        }
        catch(Exception ex)
        {

        }
    }

What I want, when I select brand, I want combobox2 to be filled with series name. But only if BrandID equal to selected combobox1 brandID.

For example, car brand AUDI, VOLVO for first combobox, and second show only model of car brand, A4/A3 and V40/V90 etc.

I can use combobox2.fill command, and also its working. But I need ID of SeriesName also becasue, I will use it at listbox to show. For example motor spec. Like 1.6lt DSG / 2.2lt Manual etc.

Hope I can explain it with my bad English. Thanks.

XPD
  • 1,121
  • 1
  • 13
  • 26
  • 1
    The Google term you are looking for is "cascading" comboboxes. All you need to do it get the id of the selected item and put that in a `WHERE` clause for the second query, then do the same thing to the second combobox that you have done with the first. – Crowcoder Jan 05 '20 at 12:58
  • oh yes many thanks. its just too simple :) i add for my second combobox WHERE BagliMarkaID=" + comboMarkaSec.SelectedValue + " " and its done. – Tanzer Kay Jan 05 '20 at 13:05
  • 1
    Now read up on SQL Injection before you do it that way in real life: https://stackoverflow.com/questions/332365/how-does-the-sql-injection-from-the-bobby-tables-xkcd-comic-work – Milney Jan 05 '20 at 15:15

0 Answers0