datatable 使用LAMBDA表达查询,过滤

     DataTable dt = new DataTable();
            DataColumn dc = new DataColumn("UserName", System.Type.GetType("System.String"));
            DataColumn dc1 = new DataColumn("UserPwd", System.Type.GetType("System.String"));
            dt.Columns.Add(dc);
            dt.Columns.Add(dc1);
            DataRow dr = dt.NewRow();
            dr["UserName"] = "22";
            dr["UserPwd"] = "33";
            dt.Rows.Add(dr);
         
            var rownumber = dt.AsEnumerable().Where<DataRow>(C=>C["UserName"].ToString()=="22");
            int row = rownumber.Count<DataRow>();
            foreach ( DataRow en in  rownumber)
            {

                Response.Write("User" + en["UserName"] + "pwd" + en["UserPwd"]);
            }

 

你可能感兴趣的:(Datatable)