DataReader question??

  • Thread starter Thread starter kevin
  • Start date Start date
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
 
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.
 
Back
Top