DataBind and SqlDataReader

  • Thread starter Thread starter Gawel
  • Start date Start date
G

Gawel

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

Is it possible that DataBind() will close automatically the reader ?
 
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.
 
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
 
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?
 
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
 
Back
Top