何时处理数据表? [英] when to dispose a datatable?
问题描述
我的表单上有一个列表框,但是我需要将它数据绑定到一个数据表,
是表单类的私有成员...所以我基本上有
Public Class MyForm
priate m_MyTable as new datatable
End Class
now我在哪里妥善处理这个?在finalize方法?我是
在一个子程序中加载表的数据,该子程序以形式执行
load,当然所有绑在它上面的命令都是用block封装的,但是
我不能将表格包装在那里因为它把它放在一个使用的块然后
数据绑定它当然它会在它退出该块时消失然后
数据绑定已经消失,所以我在课程级别取而代之,并希望
它的生命时间是表格的形式..谢谢!
I have a list box on my form, but I need to databind it to a data table that
is a private member of the form''s class... so I basically have
Public Class MyForm
priate m_MyTable as new datatable
End Class
now where would I properly dispose of this? In the finalize method? I am
loading the data for the table in a subroutine that is executed at form
load, of course all the commands tied to it are wrapped in using blocks, but
I cant wrap the table in that because it i put it in a using block then
databind it, of course it will disappear when it exits that block and then
the databinding is gone, so I made it at the class level instead and want
its life time to be that of the form.. thanks!
推荐答案
当你不再需要桌子时处理它。
你可以在FormClosing或表格中执行,如果你实施它
HTH
" Smokey Grindle" < no **** @ nospam.comwrote in message
news:uM ************** @ TK2MSFTNGP05.phx.gbl ...
Dispose it when you don''t need table anymore.
You can do that in FormClosing or in form Dispose if you implement it
HTH
"Smokey Grindle" <no****@nospam.comwrote in message
news:uM**************@TK2MSFTNGP05.phx.gbl...
>我的表单上有一个列表框,但是我需要将它数据绑定到数据表
这是表单's'类的私有成员...所以我基本上有
Public Class MyForm
priate m_MyTable as new datatable
End Class
现在我在哪里妥善处理这个?在finalize方法?我是在一个子程序中加载表格的数据,这个子程序是在形式上执行的。
load,当然所有绑在它上面的命令都是用块包裹的,
但我不能将表格包装在那里,因为我把它放在一个使用块中
然后数据绑定它,当然它会在退出该块时消失并且
然后数据绑定已经消失,所以我在课程级别取而代之而且
希望它的生命时间是表格的形式..谢谢!
>I have a list box on my form, but I need to databind it to a data table
that is a private member of the form''s class... so I basically have
Public Class MyForm
priate m_MyTable as new datatable
End Class
now where would I properly dispose of this? In the finalize method? I am
loading the data for the table in a subroutine that is executed at form
load, of course all the commands tied to it are wrapped in using blocks,
but I cant wrap the table in that because it i put it in a using block
then databind it, of course it will disappear when it exits that block and
then the databinding is gone, so I made it at the class level instead and
want its life time to be that of the form.. thanks!
只是说明你实际上并不需要处理数据表,但这是一个很好的做法。
是的,当你完成它时将其丢弃(如果你不能提前处理它,那么表格的'处置可能是一个好的地方)
-
Miha Markic [MVP C#,INETA斯洛文尼亚国家领导人]
RightHand .NET咨询&开发 www.rthand.com
博客: http://cs.rthand.com/blogs/blog_with_righthand/
" Smokey Grindle" < no **** @ nospam.comwrote in message
news:uM ************** @ TK2MSFTNGP05.phx.gbl ...
Just a note that you don''t actually need to dispose datatable, but it is a
good practice.
And yes, dispose it when you are done with it (form''s dispose might be a
good place if you can''t dispose it earlier)
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Smokey Grindle" <no****@nospam.comwrote in message
news:uM**************@TK2MSFTNGP05.phx.gbl...
>我的表单上有一个列表框,但是我需要将它数据绑定到数据表
这是表单's'类的私有成员...所以我基本上有
Public Class MyForm
priate m_MyTable as new datatable
End Class
现在我在哪里妥善处理这个?在finalize方法?我是在一个子程序中加载表格的数据,这个子程序是在形式上执行的。
load,当然所有绑在它上面的命令都是用块包裹的,
但我不能将表格包装在那里,因为我把它放在一个使用块中
然后数据绑定它,当然它会在退出该块时消失并且
然后数据绑定已经消失,所以我在课程级别取而代之而且
希望它的生命时间是表格的形式..谢谢!
>I have a list box on my form, but I need to databind it to a data table
that is a private member of the form''s class... so I basically have
Public Class MyForm
priate m_MyTable as new datatable
End Class
now where would I properly dispose of this? In the finalize method? I am
loading the data for the table in a subroutine that is executed at form
load, of course all the commands tied to it are wrapped in using blocks,
but I cant wrap the table in that because it i put it in a using block
then databind it, of course it will disappear when it exits that block and
then the databinding is gone, so I made it at the class level instead and
want its life time to be that of the form.. thanks!
在自定义控件中怎么样?应该是处理方法还是
finalize方法?我记得这是他们之间的区别,我相信
处理是立即的,并且在
对象超出范围之后的任何时候终止都会发生?
Miha Markic < miha at rthand在消息中写道
新闻:07 ******************************* *** @ microsof t.com ...
what about in a custom control? should it be in the dispose method or
finalize method? I remember this is a difference between them, i believe
that dispose is immediate and finalize can happen at any time after the
object has fallen out of scope?
"Miha Markic" <miha at rthand comwrote in message
news:07**********************************@microsof t.com...
只是说明你实际上并不需要处理数据表,但它是一个
良好做法。
是的,当你完成它时将其丢弃(如果你可以的话,表格的处理可能是一个好的地方)请稍早处理它。
-
Miha Markic [斯洛文尼亚INETA国家领导人MVP C#]
RightHand .NET咨询与开发 www.rthand.com
博客: http://cs.rthand.com/blogs/blog_with_righthand/
" Smokey Grindle" < no **** @ nospam.comwrote in message
news:uM ************** @ TK2MSFTNGP05.phx.gbl ...
Just a note that you don''t actually need to dispose datatable, but it is a
good practice.
And yes, dispose it when you are done with it (form''s dispose might be a
good place if you can''t dispose it earlier)
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"Smokey Grindle" <no****@nospam.comwrote in message
news:uM**************@TK2MSFTNGP05.phx.gbl...
>>我的表单上有一个列表框,但是我需要将它数据绑定到数据表
这是表单''的私有成员s class ...所以我基本上有公共类MyForm
priate m_MyTable作为新的数据表
End Class
现在我将在哪里妥善处理这个?在finalize方法?我在一个子程序中加载表的数据,这个子程序是以
加载的形式执行的,当然所有绑在它上面的命令都是用块包裹的,
但我不能把表包裹起来因为它我把它放在一个使用块中然后数据绑定它,当然它会在它退出那个块时消失
然后数据绑定消失了,所以我在类级别取而代之而来<希望它的生命时间是那种形式..谢谢!
>>I have a list box on my form, but I need to databind it to a data table
that is a private member of the form''s class... so I basically have
Public Class MyForm
priate m_MyTable as new datatable
End Class
now where would I properly dispose of this? In the finalize method? I am
loading the data for the table in a subroutine that is executed at form
load, of course all the commands tied to it are wrapped in using blocks,
but I cant wrap the table in that because it i put it in a using block
then databind it, of course it will disappear when it exits that block
and then the databinding is gone, so I made it at the class level instead
and want its life time to be that of the form.. thanks!
这篇关于何时处理数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!