Closing DataSets

  • Thread starter Thread starter b_naick
  • Start date Start date
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?
 
Back
Top