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
应该只有不同的价值。
和combobox从treatmentCollection
类的AutoCompleteStringCollection
对象获取值
请帮帮我?
答案 0 :(得分:3)
替换:
select Treatment from NewPatient
到此:
select distinct Treatment from NewPatient
答案 1 :(得分:0)
如果只想要不同的值,可以在sql命令中使用DISTINCT
,如;
select DISTINCT Treatment from NewPatient
答案 2 :(得分:0)
我使用此代码并且工作正常。
string query = @"Select distinct [FieldName] from [tableName]";