//箱号是否存在的检查
String[] notExists = (from d in dt.AsEnumerable() where !sdsBoxes.dt.AsEnumerable().Any(b => ((String)b["Box_No"]).Trim().Equals((d["Box_No"] as string).Trim())) select (String)d["Box_No"]).ToArray();
//箱号状态检查
notExists = sdsBoxes.dt.AsEnumerable().Where(w => (short)w["Status"] > 2).Select(w => w["Box_No"] as String).ToArray();
//箱号状态检查
notExists = sdsBoxes.dt.AsEnumerable().Where(w => (short)w["Status"] > 2).Select(w => w["Box_No"] as String).ToArray();
notExists = (from dn in dntable.AsEnumerable() where !sdsDn.dt.AsEnumerable().Any(d => ((String)dn["Dn"]).Equals(d["Dn"]) && (int)dn["Dn_Item_No"] == (int)d["Dn_Item_No"]) select dn["Dn"] as string).ToArray();
//赛选状态大于2的 DN
notExists = (from dn in sdsDn.dt.AsEnumerable() where (short)dn["Status"] > 0 select dn["Dn"] as string).ToArray();
//根据条件查找出两个表相同的 Box_No
notExists = (from box in sdsBoxes.dt.AsEnumerable()
where sdsDn.dt.AsEnumerable().Where(w => ((String)w["Dn"]).Equals(box["Dn"]) && (int)w["Dn_Item_No"] == (int)box["Dn_Item_No"] && (!((string)w["So"]).Equals(box["So"]) || (int)w["So_Item_No"] != (int)box["So_Item_No"])).Count() > 0
select box["Box_No"] as String).ToArray();
//查找出 一个表 重复的 数据
var Repeat = from Rt in ImportData.Tables[0].AsEnumerable() group Rt by Rt.Field<String>(ImportData.Tables[0].Columns[0].ColumnName) into g where g.Count() > 1 select new { box = g.Key };
//根据 DN 和 Dn_Item_No 分组 并且 DN不等于空 查出 DN,Dn_Item_No ,这组Qty 的数量和
var old = from box in sdsBoxes.dt.AsEnumerable() where box["Dn"] != DBNull.Value group box by new { dn = (String)box["Dn"], item = (int)box["Dn_Item_No"] } into g select new { g.Key, sum = g.Sum(w => (int)w["Qty"]) };
// 两表联合查询 根据 DN 和 Dn_Item_No 分组 并且 DN不等于空 查出 DN,Dn_Item_No ,这组Qty 的数量和
var add = from d in dt.AsEnumerable() join box in sdsBoxes.dt.AsEnumerable() on (String)d["Box_No"] equals box["Box_No"] where d["Dn"] != DBNull.Value group box by new { dn = (String)d["Dn"], item = (int)d["Dn_Item_No"] } into g select new { g.Key, sum = g.Sum(w => (int)w["Qty"]) };
// 根据外部条件 查找数据
var ot = old.Where(w => dn.Equals(w.Key.dn) && item == w.Key.item).SingleOrDefault();
//根据工作单排序 去掉重复
List<string> jobid = (from c in dt.AsEnumerable() orderby c.Field<string>("Doc_No") select c.Field<string>("Doc_No")).Distinct().ToList();
//获取指定的行数 (从一个表的第20行开始获取25行数据) 变为数组 再重树组获取某个字段的和
DataRow[] drs = SearchResult.AsEnumerable().Skip(20).Take(25).Where(box=>(short)box["Status"] < 99).ToArray();
drs.Sum(w => (int)w["Qty"])
//获取50行的数据 查询Package_No 的字段 装换成 数组
String[] packages = ((DataTable)GridPackage.SourceTable).AsEnumerable().Take(50).Select(w => (String)w["Package_No"]).ToArray()
// 其中最后一个未注释的是经常用到的,可以用来提取前N行,类似于SQL中的Top N。
var m = dt.AsEnumerable().Take<DataRow>(TipIndex); //提取DataTable前TipIndex条
DataTable T = m.CopyToDataTable<DataRow>();
//集合并
var except = dt2.AsEnumerable().Union(dt1.AsEnumerable(), DataRowComparer.Default);
//查询query4查询数据表中所有年龄大于20小于25的人,并且按照年龄从高到低排序
var query4 = from pl in dt.AsEnumerable( ) orderby pl.Field<int>("Age") descending where pl.Field<int>("Age") > 20 where pl.Field<int>("Age") < 25 select pl;
//两表联合查询
var query1 = from stu in dtStu.AsEnumerable( ) from score in dtScore.AsEnumerable( ) where stu.Field<int>("ScoreID") == score.Field<int>("ScoreID")
select new { Name = stu.Field<string>("Name"), MathS = score.Field<int>("Math"), Chinese = score.Field<int>("Chinese"), English = score.Field<int>("English") };