DataView view = new DataView();
view.Table = DataTableA;
view.RowFilter = "itemType = 'book'";//itemType是DataTableA中的一个字段
DataTableB= view.ToTable();
或者:
DataRow[] rows = DataTableA.Select("itemType = 'book'");
DataTableB= DataTableA.Clone();
foreach (DataRow row in rows)
{
     DataTableB.ImportRow(row);
}

或者

/// 执行DataTable中的查询返回新的DataTable
/// </summary>
/// <param name="dt">源数据DataTable</param>
/// <param name="condition">查询条件</param>
/// <returns></returns>
private DataTable GetNewDataTable(DataTable dt, string condition,string sortstr)
{
      DataTable newdt = new DataTable();
      newdt = dt.Clone();
      DataRow[] dr = dt.Select(condition,sortstr);
      for (int i = 0; i < dr.Length; i++)
      {
          newdt.ImportRow((DataRow)dr[i]);
      }
      return newdt;//返回的查询结果

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2022-01-23
  • 2022-12-23
猜你喜欢
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
相关资源
相似解决方案