• DataRow To DataTable


    1. 方式一  导入row,新表架构与原表相同,foreach前clone, newDataTable=oldDataTable.Clone();

    foreach (DataRow row in rowArray) {
       dataTable.ImportRow(row);
    }

    2. 方式二  CopyToDataTable

    DataTable dt = new DataTable();
    DataRow[] dr = dt.Select("Your string");
    DataTable dt1 = dr.CopyToDataTable();
    
    if (dr.Length > 0)
        DataTable dt1 = dr.CopyToDataTable();
    //https://msdn.microsoft.com/en-us/library/bb396189.aspx

    3. Add

    DataTable dt = new DataTable(); 
    DataRow[] dr = (DataTable)dsData.Tables[0].Select("Some Criteria");
    dt.Rows.Add(dr);

    4. DataView

    // Create a DataTable
    DataTable table = new DataTable()
    
    // Filter and Sort expressions
    string expression = "[Birth Year] >= 1983"; 
    string sortOrder = "[Birth Year] ASC";
    
    // Create a DataView using the table as its source and the filter and sort expressions
    DataView dv = new DataView(table, expression, sortOrder, DataViewRowState.CurrentRows);
    
    // Convert the DataView to a DataTable
    DataTable new_table = dv.ToTable("NewTableName");

    5. Merge

    // dtData is DataTable that contain data
    DataTable dt = dtData.Select("Condition=1").CopyToDataTable();
    
    // or existing typed DataTable dt
    dt.Merge(dtData.Select("Condition=1").CopyToDataTable());

    6.

    DataTable dt = myDataRowCollection.CopyToDataTable<DataRow>();

    7. Linq

    if (dataRows != null && dataRows.Length > 0)
    {
       dataTable = dataRows.AsEnumerable().CopyToDataTable();
    }
  • 相关阅读:
    关于s3c6410 实现opengl的分析
    ARM9和ARM11的区别
    ARM9E 和 cortex a8 NEON 优化效率的对比
    armv6 的特点
    AMBA总线新一代标准AXI分析和应用
    linux下如何模拟按键输入和模拟鼠标
    opengl es 学习
    Jlink初使用
    Allegro 制作金手指封装
    世界之窗浏览器设置google搜索[转]
  • 原文地址:https://www.cnblogs.com/dennysong/p/7953858.html
Copyright © 2020-2023  润新知