是什么让这个代码变慢 [英] What makes this code slow

查看:70
本文介绍了是什么让这个代码变慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码重置一个带有两个cbo'(组合框)和一个数据网格的表单。

第一个cbo(cboSelection)选择一个主表并过滤

第二个cbo。第二个cbo(cboView)选择辅助表

确定用于填充dataGrid的dataAdapter。两个cbo'都是

填充dataAdapters。


这段代码只是空的'datagrid,cbo'和数据集,所以用户可以

重新开始查看另一组数据。


\\

Private Sub btnResetForm_Click(ByVal sender As System .Object,ByVal e

As System.EventArgs)处理btnResetForm.Click


''清除数据网格

Me.DataGrid1 .DataSource = Nothing

Me.DataGrid1.TableStyles.Clear()


''清除数据集

_dataSet1.Clear( )


DAL.da010JobFrm.Fill(_dataSet1," tbl010Job")

''cboSelection

Me .cboSelection.DataSource = _dataSet1

Me.cboSelection.DisplayMember =" tbl010Job.JobNumber"

Me.cboSelection.ValueMember =" tbl010Job.pkJobId"


_bStillLoadingCboSelection = False


_bStillLoadingCboView = True


结束次级

//


是什么让这段代码变慢?


它就像它要抛出错误一样慢。


或者如何测试这段代码?


谢谢,

dbuchanan

解决方案

数据绑定很慢。我敢打赌你可以用你自己的代码加快组合框的价格。


您是否尝试捕获错误并查看是否

$正在生成?


-

Robbe Morris - 2004/2005 Microsoft MVP C#

EggHeadCafe'' RSS搜索引擎
http://www.eggheadcafe.com /articles/...h/default.aspx


" dbuchanan" <分贝********* @ hotmail.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...

此代码重置一个带有两个cbo(组合框)和一个数据网格的表单。
第一个cbo(cboSelection)选择一个主表并过滤
第二个cbo。第二个cbo(cboView)选择辅助表,它确定用于填充dataGrid的dataAdapter。两个cbo都是通过填充dataAdapters来填充的。

这段代码只是空的'datagrid,cbo'和数据集,所以用户可以重新开始查看另一组数据。

\\
Private Sub btnResetForm_Click(ByVal sender As System.Object,ByVal e
As System.EventArgs)处理btnResetForm.Click

''清除数据网格
Me.DataGrid1.DataSource = Nothing
Me.DataGrid1.TableStyles.Clear()

''清除数据集
_dataSet1.Clear()

DAL.da010JobFrm.Fill(_dataSet1," tbl010Job")

''cboSelection
Me.cboSelection.DataSource = _dataSet1
Me.cboSelection.DisplayMember =" tbl010Job.JobNumber"
Me.cboSelection.ValueMember =" tbl010Job.pkJobId"

_bStillLoadingCboSelection = False
_bStillLoadingCboView = True

// @

是什么让这段代码变慢了?

它的速度和它一样慢即将抛出错误。

或者如何测试此代码?

谢谢你,
dbuchanan



您好Robbe,


感谢您的回复。


我在代码中全部使用绑定对于组合框而言,它显示为

瞬间。这段代码是*特别* slloooooowwww!


我在这个街区做的一件事与

其他有点不同但它没有引发任何标志和我一起解释原因。

在其他代码中,我用这样的代码清除dataTable;


''清除数据表

_dataSet1.tbl040Cmpt.Clear()

但是在这个块中我用这段代码清除了整个数据集;


''清除数据集

_dataSet1.Clear()


这并没有给我任何标志(#1)因为只有一个

涉及的表格。我清除数据集而不是

表的原因是我不知道它将是哪些表 - 它取决于

用户选择。


另一个原因(#2)它没有向我发出一个标志是

对这个区块的子查询是即时的,即使是相同的

加载了多少个表。


任何可能导致此类行为的线索?

您是否尝试捕获错误并查看是否一个是生成?




我把这个块放在try catch块中。这没有带来任何

错误。有没有其他方法来揭露我可能会得到更多的错误

结果 - 我在捕获错误方面有点新意。


谢谢,

dbuchanan


DAL.da010JobFrm.Fill(_dataSet1," tbl010Job")

- -

Robbe Morris - 2004/2005 Microsoft MVP C#

ADO.NET对象映射器的免费源代码到数据库表并存储

程序
http://www.eggheadcafe.com/articles / ... _generator.asp


" dbuchanan" <分贝********* @ hotmail.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...

此代码重置一个带有两个cbo(组合框)和一个数据网格的表单。
第一个cbo(cboSelection)选择一个主表并过滤
第二个cbo。第二个cbo(cboView)选择辅助表,它确定用于填充dataGrid的dataAdapter。两个cbo都是通过填充dataAdapters来填充的。

这段代码只是空的'datagrid,cbo'和数据集,所以用户可以重新开始查看另一组数据。

\\
Private Sub btnResetForm_Click(ByVal sender As System.Object,ByVal e
As System.EventArgs)处理btnResetForm.Click

''清除数据网格
Me.DataGrid1.DataSource = Nothing
Me.DataGrid1.TableStyles.Clear()

''清除数据集
_dataSet1.Clear()

DAL.da010JobFrm.Fill(_dataSet1," tbl010Job")

''cboSelection
Me.cboSelection.DataSource = _dataSet1
Me.cboSelection.DisplayMember =" tbl010Job.JobNumber"
Me.cboSelection.ValueMember =" tbl010Job.pkJobId"

_bStillLoadingCboSelection = False
_bStillLoadingCboView = True

// @

是什么让这段代码变慢了?

它的速度和它一样慢即将抛出错误。

或者如何测试此代码?

谢谢你,
dbuchanan



This code resets a form with two cbo''s (comboBoxes) and one datagrid.
The first cbo (cboSelection) selects a main table and filters the
second cbo. The second cbo (cboView) selects the secondary table which
determine the dataAdapter used to fill the dataGrid. Both cbo''s are
populated by filling dataAdapters.

This code just empty''s the datagrid, cbo''s and dataset so the user can
start over to view another set of data.

\\
Private Sub btnResetForm_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnResetForm.Click

''Clear the datagrid
Me.DataGrid1.DataSource = Nothing
Me.DataGrid1.TableStyles.Clear()

''clear the dataset
_dataSet1.Clear()

DAL.da010JobFrm.Fill(_dataSet1, "tbl010Job")

''cboSelection
Me.cboSelection.DataSource = _dataSet1
Me.cboSelection.DisplayMember = "tbl010Job.JobNumber"
Me.cboSelection.ValueMember = "tbl010Job.pkJobId"

_bStillLoadingCboSelection = False

_bStillLoadingCboView = True

End Sub
//

What makes this code slow?

It is as slow as if it was about to throw an error.

Or How can I test this code?

Thank you,
dbuchanan

解决方案

Data binding is slow. I''d bet you could
load the combobox faster with your own code.

Did you try trapping errors and see if
one is being generated?

--
Robbe Morris - 2004/2005 Microsoft MVP C#
EggHeadCafe''s RSS Search Engine
http://www.eggheadcafe.com/articles/...h/default.aspx


"dbuchanan" <db*********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

This code resets a form with two cbo''s (comboBoxes) and one datagrid.
The first cbo (cboSelection) selects a main table and filters the
second cbo. The second cbo (cboView) selects the secondary table which
determine the dataAdapter used to fill the dataGrid. Both cbo''s are
populated by filling dataAdapters.

This code just empty''s the datagrid, cbo''s and dataset so the user can
start over to view another set of data.

\\
Private Sub btnResetForm_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnResetForm.Click

''Clear the datagrid
Me.DataGrid1.DataSource = Nothing
Me.DataGrid1.TableStyles.Clear()

''clear the dataset
_dataSet1.Clear()

DAL.da010JobFrm.Fill(_dataSet1, "tbl010Job")

''cboSelection
Me.cboSelection.DataSource = _dataSet1
Me.cboSelection.DisplayMember = "tbl010Job.JobNumber"
Me.cboSelection.ValueMember = "tbl010Job.pkJobId"

_bStillLoadingCboSelection = False

_bStillLoadingCboView = True

End Sub
//

What makes this code slow?

It is as slow as if it was about to throw an error.

Or How can I test this code?

Thank you,
dbuchanan



Hi Robbe,

Thank you for your reply.

I use the binding all over in my code for comboBoxes and it appears
instantaneous. This block of code is *exceptionally* slloooooowwww!

There is one thing I do a little differently in this block compared to
others but it raised no flags with me for reasons I will explain.

In other code I clear a dataTable with code like this;

''clear the datatable
_dataSet1.tbl040Cmpt.Clear()

but in this block I clear the entire dataset with this code;

''clear the dataset
_dataSet1.Clear()

This has not reaised any flags for me (#1) because there are only a
coulple of tables involved. The reason I clear the dataset instead of
tables is that I don''t know which tables it will be - it depends on
user selection.

Another reason (#2) that it has not raised a flag with me is that
subsequaint calls to this block are instantaneous even though the same
numbers of tables are loaded.

Any clues to what might cause this type of behavior?

Did you try trapping errors and see if one is being generated?



I put this block within a try catch block. That did not bring up any
errors. Is there another way to expose errors that I might get me more
results - I''m sort-of new at trapping errors.

Thank you,
dbuchanan


DAL.da010JobFrm.Fill(_dataSet1, "tbl010Job")
--
Robbe Morris - 2004/2005 Microsoft MVP C#
Free Source Code for ADO.NET Object Mapper To DataBase Tables And Stored
Procedures
http://www.eggheadcafe.com/articles/..._generator.asp


"dbuchanan" <db*********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

This code resets a form with two cbo''s (comboBoxes) and one datagrid.
The first cbo (cboSelection) selects a main table and filters the
second cbo. The second cbo (cboView) selects the secondary table which
determine the dataAdapter used to fill the dataGrid. Both cbo''s are
populated by filling dataAdapters.

This code just empty''s the datagrid, cbo''s and dataset so the user can
start over to view another set of data.

\\
Private Sub btnResetForm_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnResetForm.Click

''Clear the datagrid
Me.DataGrid1.DataSource = Nothing
Me.DataGrid1.TableStyles.Clear()

''clear the dataset
_dataSet1.Clear()

DAL.da010JobFrm.Fill(_dataSet1, "tbl010Job")

''cboSelection
Me.cboSelection.DataSource = _dataSet1
Me.cboSelection.DisplayMember = "tbl010Job.JobNumber"
Me.cboSelection.ValueMember = "tbl010Job.pkJobId"

_bStillLoadingCboSelection = False

_bStillLoadingCboView = True

End Sub
//

What makes this code slow?

It is as slow as if it was about to throw an error.

Or How can I test this code?

Thank you,
dbuchanan



这篇关于是什么让这个代码变慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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