Function return OleDbDataReader variable
If i have a function which would like to return a OleDbDataReader variable... is it possible??
I discover when my OleDbConnection is close thus the OleDbDataReader variable also contains nothing.
Attached is my function. Pls help to identify what i have did wrong....
Code:
public static OleDbDataReader DB_Query(string sSQL)
{
DOMConfigurator.Configure();
OleDbConnection DBConn = null;
OleDbCommand DBCmd = null;
OleDbDataReader DBReader = null;
using (DBConn = new OleDbConnection(DBCONNECTION))
{
try
{
DBConn.Open();
DBCmd = new OleDbCommand(sSQL, DBConn);
DBReader = DBCmd.ExecuteReader();
DBConn.Close();
}
catch (Exception e)
{
log.Error(e.Message, e);
}
finally
{
DBConn.Close();
DBConn = null;
DBCmd = null;
}
}
return DBReader;
}
Re: Function return OleDbDataReader variable
have you tried loading a datatable with the reader. If there are no rows I would think your sql statement is messed up.
Re: Function return OleDbDataReader variable
Quote:
Originally Posted by zdavis
have you tried loading a datatable with the reader. If there are no rows I would think your sql statement is messed up.
when inside the function the OleDbDataReader is still holding data... but after connection is close... it become nothing inside... so when i return that is an error in the function which call it.