执行DataTable中的查询返回新的DataTable
由原数据,根据条件可以查询出新的DataTable
1
public static DataTable FilterDataTable(DataTable dt, string condition)
2
{
3
if (condition.Trim() == "")
4
return dt;
5
else
6
{
7
DataTable newdt = new DataTable();
8
newdt = dt.Clone();
9
DataRow[] dr = dt.Select(condition);
10
for (int i = 0; i < dr.Length; i++)
11
{
12
newdt.ImportRow((DataRow)dr[i]);
13
}
14
return newdt;//返回的查询结果
15
}
16![](/Images/OutliningIndicators/InBlock.gif)
17
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)