zoukankan      html  css  js  c++  java
  • DataRow 数组转化成DataTable

    DataRow [] dr = outinfo.Tables[0].Select("stock_in_rec_id=" + this.efGrid1.Rows[this.efGrid1.RowSel]["stock_in_rec_id"].ToString() + "");

     dr.CopyToDataTable();

    有时候需要把dataset其中一个表的内容读取到DataRow,之后再复制到新的datatable应用。下面是实现的代码:

    DataRow[]转换成DataTable的方法:
    DataTable dt=new DataTable();
    DataRow[] dr=new DataRow();
    dr=GetChildRows(...);
    for(int i=0;i<dr.Length;i++)
    {
    dt.ImportRow(dr[i]);
    }
    dg.DataSource=dt;
    dg.DataBind();

    向一个DataTable批量添加DataRow时有两种办法:
    DataTable dt;
    DataTable newdt;

    for(int i = 0;i<dt.Rows.Count;i++)
    {
        newdt.Rows.Add(dt.Rows[i].ItemArray);
    }


    for(int i = 0;i<dt.Rows.Count;i++)
        {
         newdt.ImportRow(dt.Rows[i]);
        
        }

    两种方式速度很快,200条记录,50ms左右。

    但是今天,在实际开发中发现时间在5S,郁闷呀。

    检查代码,发现添加记录的DataTable一直绑定在一个DataGrid,
    改了代码:
    this.DataGrid1.DataSource = null;
    for(int i = 0;i<dt.Rows.Count;i++)
        {
         newdt.ImportRow(dt.Rows[i]);
        
        }
    this.DataGrid1.DataSource = newdt;

    速度重新快了

  • 相关阅读:
    366. Find Leaves of Binary Tree
    369. Plus One Linked List
    370. Range Addition
    411. Minimum Unique Word Abbreviation
    379. Design Phone Directory
    Permutation
    leetcode216-Combination Sum III
    百度star编程赛-练习1
    腾讯暑期实习生面试题
    素数筛选
  • 原文地址:https://www.cnblogs.com/dodui/p/1915871.html
Copyright © 2011-2022 走看看