/// <summary>
/// 将datatable的指定列名 返回指定列不重复的值的字符串集合 适用于给combox listbox添加items
/// </summary>
///<param name="dataTable">DataTable</param>
/// <param name="columnStr">dt的列名</param>
/// <returns>指定列不重复的字符串集合</returns>
public string[] GetNamesFromDataTable(DataTable dataTable, string columnStr)
{
DataView dv = da;
dataTable = dv.ToTable(true, columnStr);//关键这一句 columnStr 是datatable的列名
string[] names = new string[da];
for (int i = 0; i < names.Length; i++)
{
names[i] = da[i][0].ToString();
}
return names;
}
调用方法
string sql = "select DISTINCT reportbm, from 表名 where bm='" + 关键字+ "'";
DataTable dt = My(sql);
(GetNamesFromDataTable(dt, "reportbm"));//报修部门commbox控件 载入列表