Could I just close the connection and return the OleDbDataReader RRS feed

  • Question

  • In a function I write like this:

    public OleDbDataReader test()
        OleDbConnection conn = new OleDbConnection(connStr);
        string str = "Select * FROM Table1 ORDER BY ID ASC";
        OleDbCommand cmd = new OleDbCommand(str, conn);
        OleDbDataReader reader = cmd.ExecuteReader();
        return reader;

    But it seems the returned reader is closed and I can't use it......

    Sunday, March 3, 2013 4:31 AM


  • once you close the connection, you can't use the reader. If you want to use the result data after you close the connection, better use dataset. you can still create the dataset using the reader object with DataSet.Load method and then you can close the connection. and will keep on working on the dataset. 


    • Marked as answer by fork123x Monday, March 4, 2013 3:46 AM
    Sunday, March 3, 2013 5:30 AM