1
AutoCompleteStringCollection treatmentCollection = new AutoCompleteStringCollection();
if (con.State == ConnectionState.Closed)
{
    con.Open();
}
SqlCeCommand cmdTreatment = new SqlCeCommand("select Treatment from NewPatient", con);
SqlCeDataReader readerTreatment = cmdTreatment.ExecuteReader();
if (readerTreatment.Read() == true)
{
    while (readerTreatment.Read())
    {
        treatmentCollection.Add(readerTreatment["Treatment"].ToString());
    }
}
comboBox2.AutoCompleteMode = AutoCompleteMode.Suggest;
comboBox2.AutoCompleteSource = AutoCompleteSource.CustomSource;
comboBox2.AutoCompleteCustomSource = treatmentCollection;
if (con.State == ConnectionState.Open)
{
    con.Close();
}

我希望combobox2应该只有不同的价值。treatmentCollection并且组合框从类对象中获取价值AutoCompleteStringCollection请帮助我?

4

3 回答 3

3

代替:

select Treatment from NewPatient

对此:

select distinct Treatment from NewPatient
于 2013-04-29T10:26:15.717 回答
0

如果你只想要不同的值,你可以DISTINCT在你的 sql 命令中使用,比如;

select DISTINCT Treatment from NewPatient

查看Eliminating Duplicates with DISTINCT

于 2013-04-29T10:27:51.137 回答
0

我使用使用此代码,它工作正常。

string query = @"Select distinct [FieldName] from [tableName]";
于 2016-07-10T15:28:05.457 回答