CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Posts
    568

    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;
            }

  2. #2
    Join Date
    Sep 2007
    Posts
    82

    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.

  3. #3
    Join Date
    Feb 2005
    Posts
    568

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured