Fill ComboBox without repetitions

1

I'm trying to fill a ComboBox from a db , but ComboBox is populated with many repeated items!

OleDbConnection Con = new OleDbConnection();
Con.ConnectionString = Properties.Settings.Default.dbCombo;

Con.Open();
OleDbCommand Cmm = new OleDbCommand();
Cmm.CommandText = "SELECT NomeInv FROM tbFev;
Cmm.CommandType = CommandType.Text;
Cmm.Connection = Con;
OleDbDataReader DR;
DR = Cmm.ExecuteReader();

DataTable dt = new DataTable();
dt.Load(DR);

DataView dv = new DataView(dt, "", "NomeInv", DataViewRowState.OriginalRows);
comboBox1.DataSource = dv;
comboBox1.DisplayMember = "NomeInv";
comboBox1.ValueMember = "";

Con.Close();

This is where all the information in the NomeInv field, including repeated, is coming.

Is there any code to prevent this?

    
asked by anonymous 26.08.2016 / 19:49

1 answer

2

Use DISTINCT in your SELECT .

In this way:

SELECT DISTINCT NomeInv FROM tbFev;

All completely identical lines will be joined by the expression "distinct".

    
26.08.2016 / 20:04