关于Linq to DataSet

代码
  private PagedDataSource BindMethod(PagedDataSource pds, string keyword)
        {
            OthersTradeBo bo 
= null;
            
try
            {
                bo 
= new OthersTradeBo();
                DataSet ds 
= responseDataSet(bo);
                DataTable dt 
= ds.Tables[0];
                
//空白时候,搜索全部
                if (string.IsNullOrEmpty(keyword))
                {
                    DataView dv 
= ds.Tables[0].DefaultView; 
                    pds.DataSource 
= dv;//视图用于绑定到页面
                    _recordCount = ds.Tables[0].DefaultView.Count;
                }
                
else
                {
                    var temp 
= from c in dt.AsEnumerable() where c.Field<String>("InformationTitle").Contains(keyword) select c;
                    
//dt.AsEnumerable().Where(c => c.Field<String>("InformationTitle").Contains(keyword));  //另外的写法,效果一样
                    pds.DataSource = temp.AsDataView();
                    _recordCount 
= temp.Count();
                }
                bindPageButtons(_recordCount, _pagesize);
                
return pds;
            }
            
finally { if (bo != null)bo.Dispose(); }
        }

其中代码片段。

原文地址:https://www.cnblogs.com/drek_blog/p/1709939.html