ExecuteNonQuery() vs ExecuteReader()

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

I think that in the case of calling SPROC, both methods will execute the
SPROC, but ExecuteReader() will return the resultset from the last SELECT
query contained in the SPROC, should it contain one. Is this correct?
 
They are used for different purposes.

ExecuteReader will generate a Datareader based on a SQL
Query...not a good choice for DDL, Insert and Delete
statements.

ExecuteNonQuery is used for INserts, Delete, DDL and most
other things that don't return a resultset. I believe it
has a recordsaffected property, but it doesn't return a
value per se from the Database.

This link discusses them ni a little more depth.

Good Luck,

Bill
 
Back
Top