利用DataSet、DataTable、DataView按照自定义条件过滤数据
DataView的RowFilter与RowStateFilter分别可以按照自定义条件、DataViewRowState的记录行状态来过滤数据(有时测试不太好使,可能因人而异哈哈。。)。
例:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
myView.RowFilter = "name<> 'World' and name <> 'Hello' and corpid>400";
for(int t=0;t<myView.Count;t++)
{
TextBox2.Text += myView[t]["name"].ToString()+"\r\n";
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
myView.RowStateFilter=DataViewRowState.Added | DataViewRowState.ModifiedCurrent;
for(int i = 0;i < myView.Count ;i++)
{
TextBox2.Text += myView[i]["name"].ToString()+"\r\n";
}
利用DataSet过滤数据:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
DataRow[] drUserUrl = dsUserUrl.Tables[0].Select("UserName='北飘'");
DataSet dsUserUrl = new DataSet();
if(drUserUrl.Length>0)
{
dsUserUrl.Merge(drUserUrl);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//利用RowState来过滤
DataSet dsTmpUserUrl = dsUserUrl.GetChanges(DataRowState.Unchanged);
例:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
利用DataSet过滤数据:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)