SqlDataReader recordsaffected

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
 
W

William Ryan

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
 
C

Chris Leffer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top