DataTable 取特定的几列

如下:

DataTable dts = DBConn.GetSqlData(sql);
            dts.TableName = "dts";
 DataTable dt = dts.DefaultView.ToTable("dts", false, "ProductionOrderno", "GreInvNo", "productionqty", "greigenum");//fasle :不去重 ProductionOrderno、greigenum、productionqty、productionqty:列名

 

去重:

 CardNos = GetDistinctSelf(CardNos, "卡号");

 public static DataTable GetDistinctSelf(DataTable SourceDt, string filedName)
        {
            for (int i = SourceDt.Rows.Count - 1; i > 0; i--)
            {
                DataRow[] rows = SourceDt.Select(string.Format("{0}='{1}'", filedName, SourceDt.Rows[i][filedName]));
                if (rows.Length > 1)
                {
                    SourceDt.Rows.RemoveAt(i);
                }
            }
            return SourceDt;
        }

 

posted on 2021-02-19 16:43  RookieBoy666  阅读(559)  评论(0编辑  收藏  举报