ImportRow遇见的问题

向一个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;

速度重新快了
呵呵
看来数据绑定还是很慢地.....

posted on 2004-04-28 18:26  newLee  阅读(3577)  评论(2编辑  收藏  举报

导航