每次rst.close后我都需要使用Nothing吗? [英] Do I need to use Nothing after each rst.close?
问题描述
我的程序如下所示:
Dim db作为DAO.Database,rst作为DAO.Recordset
设置db = CurrentDb
设置rst = db.OpenRecordset(" SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =
''Invoice''")
做一些工作
rst.close
设置rst = db.OpenRecordset(" SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =
''Credit备忘录''")
做一些工作
rst.close
这种模式重复几次然后
rst.close
Set rst = Nothing
设置db = Nothing
我是否需要在每个rst.close之后或者仅在最终
关闭之后将rst设置为Nothing?
On周四,2004年1月15日17:33:48 GMT,Karl Irvin < 88 ******** @ comcast.net>写道:
我的程序看起来像这样:
Dim db作为DAO.Database,rst作为DAO.Recordset
设置db = CurrentDb
设置rst = db.OpenRecordset(" SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =
''Invoice''")
做一些工作
rst.close
设置rst = db.OpenRecordset(" SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =
''Credit Memo''")
做一些工作
rst.close <这个模式再重复几次然后
rst.close
设置rst = Nothing
设置db = Nothing
>我是否需要在每次rst.close之后或者仅在最后
关闭之后将rst设置为Nothing?
你正在做的是正确的,它这是大多数人的所作所为。就个人而言,
虽然,我试图更加严谨,同时将所有内容设置为Nothing(类似于需要明确设置为Nothing的各种内容)我关闭了
吧。因为你可以使用冒号分隔符将语句放在同一行上,所以我通常会说...... b / b
rst。关闭:设置rst = Nothing
还有一个问题,如果你不介意我插入...
你需要rst.Close还是你可以直接设置rst = Nothing ???
谢谢
Chris
" Steve Jorgensen" <无**** @ nospam.nospam>在消息中写道
新闻:bh ******************************** @ 4ax.com ...2004年1月15日星期四17:33:48 GMT,Karl Irvin < 88 ******** @ comcast.net>
写道:我的程序看起来像这样:
Dim db作为DAO.Database,rst作为DAO.Recordset
设置db = CurrentDb
设置rst = db.OpenRecordset(" SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType
=''Invoice''")
做一些工作
rst.close
设置rst = db.OpenRecordset(" SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType
=''Credit Memo''")
做一些工作
rst.close <这个模式再重复几次然后
rst.close
设置rst = Nothing
设置db = Nothing
>我是否需要在每次rst.close之后或者仅在
最后关闭之后将rst设置为Nothing?
您正在做的是正确的,这是大多数人所做的。就个人而言,尽管如此,我尝试更加严谨,同时将所有内容设置为Nothing(
种类需要明确设置为Nothing的内容)我b $ b关闭它。由于您可以使用冒号
分隔符将语句放在同一行上,我通常会说...
rst.Close:Set rst = Nothing
ya******@yahoo.com (Yamafopa!)写道
< bu ********** @ news.storm.ca>:
你需要rst.Close还是你能来吗?简单地直接设置rst =
没什么???
是的,你需要同时做这两件事,因为它们是完全不同的东西:
1.设置rst.Close释放记录集的内存结构
存储。
2.设置rst = Nothing清除指向该内存结构的指针,
但不一定要释放它。
记录集变量是指向内存结构的指针,所以
清除指针是一个单独的操作,不会破坏
内存结构。
显然,你已经有了在清除
指针之前执行.Close。
-
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
My program looks like this:
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =
''Invoice''")
Do some work
rst.close
Set rst = db.OpenRecordset("SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =
''Credit Memo''")
Do some work
rst.close
this pattern is repeated several more times and then
rst.close
Set rst = Nothing
Set db = Nothing
Do I need to set rst to Nothing after each rst.close or only after the final
close?
On Thu, 15 Jan 2004 17:33:48 GMT, "Karl Irvin" <88********@comcast.net> wrote:
My program looks like this:
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =
''Invoice''")
Do some work
rst.close
Set rst = db.OpenRecordset("SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =
''Credit Memo''")
Do some work
rst.close
this pattern is repeated several more times and then
rst.close
Set rst = Nothing
Set db = Nothing
Do I need to set rst to Nothing after each rst.close or only after the final
close?
What you are doing is correct, and it''s what most people do. Personally,
though, I try to be more rigorous and set everything to Nothing (of the kinds
of things that need to be explicitly set to Nothing) at the same time I close
it. Since you can put statements on the same line using a colon separator, I
usually say...
rst.Close: Set rst = Nothing
One more question, if you don''t mind me butting in...
Do you need rst.Close or can you simply to straight to Set rst = Nothing???
Thanks
Chris
"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:bh********************************@4ax.com...On Thu, 15 Jan 2004 17:33:48 GMT, "Karl Irvin" <88********@comcast.net> wrote:My program looks like this:
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =''Invoice''")
Do some work
rst.close
Set rst = db.OpenRecordset("SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType =''Credit Memo''")
Do some work
rst.close
this pattern is repeated several more times and then
rst.close
Set rst = Nothing
Set db = Nothing
Do I need to set rst to Nothing after each rst.close or only after the finalclose?
What you are doing is correct, and it''s what most people do. Personally,
though, I try to be more rigorous and set everything to Nothing (of the
kinds of things that need to be explicitly set to Nothing) at the same time I close it. Since you can put statements on the same line using a colon separator, I usually say...
rst.Close: Set rst = Nothing
ya******@yahoo.com (Yamafopa!) wrote in
<bu**********@news.storm.ca>:
Do you need rst.Close or can you simply to straight to Set rst =
Nothing???
Yes, you need to do both, because they are too different things:
1. Set rst.Close releases the memory structures the recordset was
stored in.
2. Set rst = Nothing clears the pointer to that memory structure,
but doesn''t necessarily release it.
The recordset variable is a pointer to a memory structure, so
clearing the pointer is a separate operation from destroying that
memory structure.
And, obviously, you''ve got to do the .Close before clearing the
pointer.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
这篇关于每次rst.close后我都需要使用Nothing吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!