C#赋值给DataRow [“haswhatnots”] = hasWhatnots是很慢的 [英] C# Assigning a value to DataRow["haswhatnots"] = hasWhatnots is awful slow

查看:524
本文介绍了C#赋值给DataRow [“haswhatnots”] = hasWhatnots是很慢的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#为DataRow分配一个值[haswhatnots] = hasWhatnots很慢。 hasWhatnots是一个布尔值。

C# Assigning a value to DataRow["haswhatnots"] = hasWhatnots is awful slow. hasWhatnots is a boolean value.

我已经对这一行进行了剖析,560000次点击执行时间是82秒。当然,分析器对性能有一定的影响,但是性能仍然很慢啊!

I have profiled this line and with 560000 hits the execution time is 82 seconds. Of course the profiler has some effect on the performance, but still the performance of this is grazy slow!

任何关于这个问题的提示。 DataRow是绑定到绑定到DataGridView.Datasource的BindingSource的DataTable的一部分。

Any hints on the issue. The DataRow is part of a DataTable which is bound to BindingSource that is bound to DataGridView.Datasource.

推荐答案

(编辑:只是看到你是数据绑定)
首先要禁用数据-捆绑;可能将源设置为null,然后重新绑定。 BindingSource SuspendBinding() ResumeBinding() code> ResetBindings()为此。

(edit: only just saw that you are data-binding) The first thing to try is disabling data-binding; perhaps set the source to null and re-bind afterwards. BindingSource has SuspendBinding(), ResumeBinding() and ResetBindings() for this.

如果真正的问题只是查找,您可以使用 DataColumn ,然后使用:

If the real problem is just lookup, you could take a snap of the DataColumn, and use:

// early code, once only...
DataColumn col = table.Columns["haswhatnots"];

// "real" code, perhaps in a loop
row[col] = hasWhatnots;

我似乎记得这是最快的路线(字符串重载找到列表中的DataColumn

I seem to recall that this is the fastest route (the string overload locates the DataColumn from the list).

或者 - 使用 DataTable ; -p

Alternatively - use a class model instead of DataTable ;-p

这篇关于C#赋值给DataRow [“haswhatnots”] = hasWhatnots是很慢的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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