DataBind and SqlDataReader

G

Gawel

control.DataSource = reader;
control.DataBind();

Is it possible that DataBind() will close automatically the reader ?
 
R

Raterus

back up to when you execute your reader from the command object
Dim reader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

This essentially closes the connection when the reader is closed.
 
G

Gawel

Thanks for answer
back up to when you execute your reader from the command object
Dim reader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
This essentially closes the connection when the reader is closed.
But I still need to call Colse() on reader ?
And this is what I want to avoid.

Gawel
 
S

Scott Allen

Hi Gawel:

Yes, you'll still need to invoke Close, or Dispose on the
SqlDataReader. It's absolutely critical to do so if you are using
ExecuteReader with CommandBehavior.CloseConnection. If you want to
avoid invoking Close, perhaps using a DataSet would suit your
application better?
 
G

Gawel

Yes, you'll still need to invoke Close, or Dispose on the
SqlDataReader. It's absolutely critical to do so if you are using
ExecuteReader with CommandBehavior.CloseConnection. If you want to
avoid invoking Close, perhaps using a DataSet would suit your
application better?

Yes, I think about converitng each datareader to the datatable.
It can be done without knowledge about the content of the data and
is one of possible solutions. It will be great to have
DataBind(Behevior.CloseAfterFetching)

Gawel
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top