DataReader question??

K

kevin

hi all

from some ado.net book, I saw some example on the dataReader. there is a
class called DB and there is a method that returns a dataReader, now my
question is
in order for the dataReader to retrieve data from the data source, the
connection must be open, so when call to the
..Close() method, will it close the connetion too?

Kevin
 
M

Marina

If you use the CommandBehavior.CloseConnection argument when executing the
query.

However, in reality, you almost never want to be returning datareaders to
consumers of your class. This puts the burden of closing the datareader (and
thus the connection) on them - and you almost never want to rely on them
doing this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top