我最后用了Dataview的RowFilter属性完成
DataRow[] rows1 = dt2.Select("姓名='张' and 编号=1");
DataRow[] rows2 = dt2.Select("姓名='张' or 成绩>'60'");
是不是这样的?好久没用过DataTable
var dt1 = new DataTable(); var dt2 = new DataTable(); var query = from a in dt1.AsEnumerable() join b in dt2.AsEnumerable() on a["id"].ToString() equals b["aid"].ToString() //where a["id"].ToString() == "查询的Id" select new { //查询结果字段 Id = a["id"] }; Console.ReadKey();
1 var a = dt2.AsEnumerable().Where(x => x["ID"].Equals(id)).FirstOrDefault();