Hi,
Generally, we use 1. connectionopen 2. Execute Command 3. close connection.
In case of SqlDataReader, it binds the data unless the connection is alive. Hence,
If you want to control the database connection behavior explicitly, simply call the execute Reader method without any parameter.
just as in (2) objDataReader = objCommand.ExecuteReader()
If you want to set the connection to be closed, as soon as the reader is closed. pass the (CommandBehaviour.CloseConnection())
just as in (1) objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
Coming to the second thing,
you may attach the data reader as a datasource and populate.
Awesome Coding !! :)
Thiru, if this helps please login to Mark As Answer. | Alert Moderator