tags:

views:

15

answers:

2

hi

i have this code for fill combo-box

SQL = "SELECT DISTINCT Name,Num FROM MyTbl order by Name";
            adp = new OracleDataAdapter(SQL, Conn);
            adp.Fill(dsNa, "MyTbl");
            adp.Dispose();
            comFna.DataSource = dsNa.Tables[0];
            comFna.DisplayMember = dsNa.Tables[0].Columns[0].ColumnName;
            comFna.ValueMember = dsNa.Tables[0].Columns[1].ColumnName;

but after inserting new Name - i dont see hem

and after i run this code again - i see duplicity records (only in the combobox)

how to solve this ? (i work on C# Winforms)

thank's in advance

+1  A: 

when you add new name to database you have two choices: 1) create a new item with given name (and num value) and insert it into combobox items collection. 2) re-load combobox from database (which you are using)

the only problem is that you need to clear combobox items or set its datasource to null before re-binding it.

adp.Dispose();
comFna.DataSource = null; //ADD THIS LINE HERE OR comFna.Items.Clear();
comFna.DataSource = dsNa.Tables[0];
comFna.DisplayMember = dsNa.Tables[0].Columns[0].ColumnName;
comFna.ValueMember = dsNa.Tables[0].Columns[1].ColumnName;
TheVillageIdiot
A: 
comFna.Items.Clear();

before filling your comboBox, use this code to remove old items, and then re-fill it.

Serkan Hekimoglu