日期:2014-05-20 浏览次数:20896 次
var dataResult = from datatable in dt.AsEnumerable() where datatable.Field<string>("StaffNo") == TransF_Supervisor select datatable.Field<string>("StaffNo");
DataTable dt = new DataTable(); var dataResult = from datatable in dt.AsEnumerable() where datatable.Field<string>("StaffNo") == "0001" select datatable;
------解决方案--------------------
如果只是判断的话,可以这样:
bool b=dt.AsEnumerable().Any(d=>d.Field<string>("StaffNo") == "0001");
------解决方案--------------------
1:Linq 可以判断是否有,并且取得其值
var dataResult =( from datatable in dt.AsEnumerable()
where datatable.Field<string>("StaffNo") == TransF_Supervisor
select datatable.Field<string>("StaffNo")).FirstOrDefault();
2:lamda 仅仅判断是否存在
var reslut = dt.AsEnumerable().Any(c => c.Field<string>("StaffNo") == TransF_Supervisor
);