locked
reloading datasource by cache RRS feed

  • Question

  • User981326454 posted

    Been a long day already and just trying to make sure I'm not crazy here.  From what I understand the DataReader is the fastest to iterate through data compared to DataSet and DataTable.

    I'm pulling some DB data (typically no more than about 5-15 rows) and then doing the basic: 

    While(mydataReader.Read()) { ..so so some looping work here based on returned rows }

    The rows returned are for creating some dynamic content and not simply to load a DataGrid for instance or this would be a non-issue.  I'm also caching the result in a DataTable for the next time its needed.  Since you cant (that I'm aware of) "reload" per say the dataReader from the cached dataTable I now have to either redo my logic to NOT initally use the DataReader (which I believe is the fastest and most efficient) and simply iterate through the original resultSet via a DataTable OR I'd have to have seperate Looping Logic to use the cached result.

    Does this sound correct?  Is there a way to reload a DataReader from cache (I doubt it, but figured I'd ask)?  Is there a better approach for this? 

    Friday, April 12, 2013 4:06 PM

Answers

  • User-1241139641 posted

    DataTable would work fine.

    Anything that stores the value you've already retrieved from the database should be ok.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 12, 2013 4:24 PM

All replies

  • User-1241139641 posted

    Correct, you wouldn't cache a DataReader. The DataReader is forward-only so once you read a record it's lost. Also, it uses an open database connection which means you can't really cache it anyways.

    Friday, April 12, 2013 4:13 PM
  • User981326454 posted

    Yep...a big no no.  So in a situation where you want to cache that result to use again, but your logic is setup to iterate via a dataReader does one simply NOT use a dataReader and swap it out by iterating through a DataTable / DataSet?

    I'm guessing that is the anwser just wanted to make sure I wasn't nuts

    Friday, April 12, 2013 4:15 PM
  • User-1241139641 posted

    DataTable would work fine.

    Anything that stores the value you've already retrieved from the database should be ok.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 12, 2013 4:24 PM