执行DataTable中的查询返回新的DataTable

由原数据,根据条件可以查询出新的DataTable

 1public 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
17        }
posted @ 2007-09-26 08:48  sunfishlu  阅读(281)  评论(0编辑  收藏  举报