SqlDataReader recordsaffected

  • Thread starter Thread starter Chris Leffer
  • Start date Start date
C

Chris Leffer

Hi.

Just reading about the sqldatareader object I am confused about the
recordsaffected property.

The example on the help docs use a procedure with some inserts and a
select. Can I use a datareader object to run sql commands that does not
return records? What is the advantage of using a
datareader.recordsaffected instead of command.executenonquery, since the
later also can give me the records affected?

Regards,

Chris Leffer
 
Use ExecuteNonQuery if you aren't returning any rows. RecordsAffected is a
property whereas .ExecuteNonQuery is a method, so they aren't the same
thing. ExecuteNonQuery doesn't return a resultset but it will return
Output Parameters and Return Values. Remember though that if you fire a
SELECT statement alone, and it returns say 100 records, you won't know this
from RecordsAffected...you'll hvae to iterate through the reader to find
this out.

HTH

Bill
 
Hi William
Remember though that if you fire a SELECT statement >alone, and it
returns say 100 records, you won't know this
from RecordsAffected...you'll hvae to iterate through the >reader to
find this out.

That is the nature of my question. If I call a stored procedure that do
an insert and return a select, the datareader.recordsaffected returns
the number of rows affected by the insert, and the resultset. So, I am
wondering if it is possible to use a datareader for procedures that only
inserts or updates data and get the rows affected.

Thanks for your help.

Chris Leffer
 
Back
Top