Closing DataSets

B

b_naick

I have a helper class in my application which manages all my DB
Connections.

Some of these functions return a OleDbDataReader object while others
return a DataSet. When I issue a command.executeReader call, I send as
input "CommandBehavior.CloseConnection".

For example,

public OleDbDataReader ExecuteQuery(string sql)
{
if (sql != "")
{
myConnection = new OleDbConnection(connStr);
myConnection.Open();
myCommand = new OleDbCommand(sql, myConnection);
myReader = myCommand.ExecuteReade(CommandBehavior.CloseConnection);
}
return myReader;
}

so when a page uses this function and gets back a reader, that page
will implicity close the connection when it closes the reader.

How can I implement the same for a DataSet. If this class returns a
DataSet to some other page, how can i ensure that the connection is
closed with the dataset is cleared?
 

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