dt.Select()
string strExpr = "Country = 'zh-CN ' ";
string strSort = "CompanyName DESC ";
DataRow [] resultRows = table.Select(strExpr, strSort);
string strSort = "CompanyName DESC ";
DataRow [] resultRows = table.Select(strExpr, strSort);
DataRow[] drArr = dt.Select("C1=’abc’");//查询
还可以这样操作:
DataRow[] drArr = dt.Select("C1 LIKE ’abc%’");//模糊查询
DataRow[] drArr = dt.Select("’abc’ LIKE C1 + ’%’", "C2 DESC");//另一种模糊查询的方法
DataRow[] drArr = dt.Select("C1=’abc’", "C2 DESC");//排序
DataTable dtNew = dt.Clone();
for (int i = 0; i < drArr.Length; i++)
{
dtNew.ImportRow(drArr[i]);
}
行数统计:
DataRow[] DrCount=dt.Select("PCState='在用'");
int m=DrCount.Count();
or:
int m=dt.AsEnumerable().Count(d=>d.Field<string>["State"]=="在用");