1、将DataTable中的列转换成唯一值的数组,

2、调用如下转换函数即可

public string[] ConvertList(DataTable dt, string colName)
        {
            List<string> list = new List<string>();
            DataTable dtNew = dt.DefaultView.ToTable(true, colName);
            dtNew .DefaultView.Sort = colName;
            dtNew = dtNew .DefaultView.ToTable();
            foreach (DataRow dr in dtNew .Rows)
            {
                if (dr[0] != DBNull.Value && dr[0] != null)
                {
                    list.Add(dr[0].ToString());
                }
            }
            return list.ToArray();
        }

3、定义数组调用函数后返回满足dt查询列的对应数组集合。

更多推荐