现在的位置: 首页 > 综合 > 正文

Linq to DataTable 多条件查询

2013年02月19日 ⁄ 综合 ⁄ 共 349字 ⁄ 字号 评论关闭
string keyword=this.txt_keyword.Text;
string tempstr=this.txt_tempstr.Text;
var q=from n in NS       //这个只是 个测试写法,因为时间紧就没完整的贴出来,后面的字段值在集合里面并不一定存在
where (!string.IsNullOrEmpty(keyword) ? (news.Field<string>("Title") != null&&news.Field<double>("Title") == keyword) : true)
&& (!string.IsNullOrEmpty(tempstr) ? news.Field<string>("cccField") == tempstr : true) 
 
条件多的话,同理按上面方式添加&&

抱歉!评论已关闭.