5

接続を閉じる前に常に DataReader を閉じる必要がありますか、それとも単に接続を閉じても問題ありませんか? 接続を閉じるだけで、効果的にリーダーを閉じますか?

(これは c#.net 3.5 用です)

ありがとう!

4

3 に答える 3

6

Aside from making your intent clear, there is this from the Microsoft documentation (Retrieving Data Using a DataReader (ADO.NET)):

You should always call the Close method when you have finished using the DataReader object.

于 2010-03-25T21:15:25.123 に答える
0

Close the DataReader as well.

imo. if it implements IDisposable , or has a .close() method or a similar construct that the documentation states you should call when you're done with this instance - do it. Don't rely on something else to take care of it for you - unless the documentation explicitly states that it does. For a DataReader/DbConnection - the docs doesn't mention anything like this.

于 2010-03-25T21:15:12.813 に答える
0

dispose() を呼び出す c# using ステートメントを活用することをお勧めします。ここにまともな説明があります。

ステートメントの使用

于 2010-03-25T21:19:03.417 に答える