Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The answer to that can be quite broad.</p> <p>Essentially, the major difference for me that usually influences my decisions on which to use is that with a SQLDataReader, you are "streaming" data from the database. With a SQLDataAdapter, you are extracting the data from the database into an object that can itself be queried further, as well as performing CRUD operations on. </p> <p>Obviously with a stream of data SQLDataReader is MUCH faster, but you can only process one record at a time. With a SQLDataAdapter, you have a complete collection of the matching rows to your query from the database to work with/pass through your code.</p> <p><strong>WARNING:</strong> If you are using a SQLDataReader, ALWAYS, ALWAYS, ALWAYS make sure that you write proper code to close the connection since you are keeping the connection open with the SQLDataReader. Failure to do this, or proper error handling to close the connection in case of an error in processing the results will <strong>CRIPPLE</strong> your application with connection leaks.</p> <p>Pardon my VB, but this is the minimum amount of code you should have when using a SqlDataReader:</p> <pre><code>Using cn As New SqlConnection("..."), _ cmd As New SqlCommand("...", cn) cn.Open() Using rdr As SqlDataReader = cmd.ExecuteReader() While rdr.Read() ''# ... End While End Using End Using </code></pre> <p>equivalent C#:</p> <pre><code>using (var cn = new SqlConnection("...")) using (var cmd = new SqlCommand("...")) { cn.Open(); using(var rdr = cmd.ExecuteReader()) { while(rdr.Read()) { //... } } } </code></pre>
 

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