如何减少以下查询的时间 [英] how reduce time consuming of below query

查看:90
本文介绍了如何减少以下查询的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


 List< DataRow> list = dtxml.AsEnumerable().Take(r).ToList();
 foreach (DataRow dRremove  列表中的)
{
    dtxml.Rows.Remove(dRremove);
    dtxml.AcceptChanges();
} 


上面的数据表删除需要更多的时间.如何减少耗时.

解决方案

您的.AcceptChanges()调用不应在每个操作之后执行.这将导致每次迭代的开销,该开销仅应在流程结束时执行一次.将其移出foreach循环并直接在其之后.数据表例如(仅是草图):

 DataView testView =  DataView(dtxml);
testView.RowFilter = " ;
DataTable testTable = TestView.ToTable(" ); 


Hi,

List<DataRow> list = dtxml.AsEnumerable().Take(r).ToList();
foreach (DataRow dRremove in list)
{
    dtxml.Rows.Remove(dRremove);
    dtxml.AcceptChanges();
}


The above datatable deletion take much more time. How to reduce time consuming.

解决方案

Your .AcceptChanges() call should not be performed after every action. This is causing overhead on every iteration that only should be done once at the end of the process. Move it outside of and directly after your foreach loop.


Another possibility could be that you define a query which returns the rows you want to have in the result and using a dataview you create a new datatableFor example something like (just a sketch):

DataView testView = new DataView(dtxml);
testView.RowFilter = "...";
DataTable testTable = TestView.ToTable("NewTable");


这篇关于如何减少以下查询的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆