我的sql中有一个表,例如名称和城市。
我想创建一个Select Command来获取所有城市,并从结果中删除重复项。
我正在使用的选择:
string citiesSelect = "SELECT [city] FROM [people] ORDER BY [city]";
CitiesDataSource.SelectCommand = citiesSelect;
CitiesDataSource.Select(DataSourceSelectArguments.Empty);
DropDownList2.DataSourceID = CitiesDataSource.ID;
答案 0 :(得分:4)
使用DISTINCT。
string citiesSelect = "SELECT DISTINCT [city] FROM [people] ORDER BY [city]";
CitiesDataSource.SelectCommand = citiesSelect;
CitiesDataSource.Select(DataSourceSelectArguments.Empty);
DropDownList2.DataSourceID = CitiesDataSource.ID;
答案 1 :(得分:0)
考虑以下一行:
string citiesSelect = "SELECT DISTINCT [city] FROM [people] ORDER BY [city]";
答案 2 :(得分:0)