DataTable.Select用法-返回新的DataTable
作者:互联网
string condition = @"MaterialNum='" + dataTable.Rows[i]["MaterialNum"].ToString() + "'" + @" and SupplierName='" + dataTable.Rows[i]["SupplierName"].ToString() + "'"; DataTable newdt = GetNewDataTable(dataTable2, condition); /// <summary> /// 执行DataTable中的查询返回新的DataTable /// </summary> /// <param name="dt"></param> /// <param name="condition"></param> /// <returns></returns> private DataTable GetNewDataTable(DataTable dt, string condition) { DataTable newdt = new DataTable(); newdt = dt.Clone(); DataRow[] dr = dt.Select(condition); if (dr == null || dr.Length == 0) return null; for (int i = 0; i < dr.Length; i++) { newdt.ImportRow((DataRow)dr[i]); } return newdt;//返回的查询结果 }
标签:Rows,newdt,Select,dt,用法,dr,DataTable,condition 来源: https://www.cnblogs.com/fyssl/p/16419094.html