Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The choice really doesn't depend on C# itself. It comes down to a balance between:</p> <ol> <li>How often do you use the data in your code?</li> <li>Does the data ever change (and do you care if it does)?</li> <li>What's the relative (time) cost of getting the data again, compared to everything else your code does?</li> <li>How much value do you put on <em>performance</em>, versus <em>developer effort/time</em> (for this particular application)?</li> </ol> <p>As a general rule: for production applications, where the data doesn't change often, I would probably create the DataTable once and then hold onto the reference as you mention. I would also consider putting the data in a typed collection/list/dictionary, instead of the generic DataTable class, if nothing else because it's easier to let the compiler catch my typing mistakes.</p> <p>For a simple utility you run for yourself that "starts, does its thing and ends", it's probably not worth the effort.</p> <p>You are asking about Windows CE. In that particular care, I would most likely do the query only once and hold onto the results. Mobile OSs have extra constraints in batteries and space that desktop software doesn't have. Basically, a mobile OS makes bullet #4 much more important.</p> <p>Everytime you add another retrieval call from SQL, you make calls to external libraries more often, which means you are probably running longer, allocating and releasing more memory more often (which adds fragmentation), and possibly causing the database to be re-read from Flash memory. it's most likely a lot better to hold onto the data once you have it, assuming that you can (see bullet #2).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload