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;
        }
原文地址:https://www.cnblogs.com/tiancaige/p/14416875.html