sqldatareader and updates

D

Dune

I'm a bit confused as to how the sqldatareader oughta be
used...

so far, I've just assumed that it was only used with
SELECT statements and "Provides a means of reading a
forward-only stream of rows from a SQL Server database."
(from msdn)

however, sqldatareader has a RecordsAffected property and
the documentation says this property is "The number of
rows changed, inserted, or deleted; 0 if no rows were
affected or the statement failed; and -1 for SELECT
statements."

....implying that sqldatareader can be used to
update/insert/delete. If this is so and given
sqldatareader's good performance, does this mean that
updating with a sqldatareader is faster than updating
using the command object's ExecuteNonQuery()?
 
W

William \(Bill\) Vaughn

The Command object supports a number of methods--each used for a specific
purpose.
* The ExecuteReader is designed to execute a query and return a rowset
in the form of a DataReader (stream).
* The ExecuteNonQuery is designed to execute a query and return the
rowsaffected value from the action query executed, but no rowset.
* The ExecuteScalar is designed to execute the query and return the
first column of the first row returned and discard the rest.
* The ExecuteXMLReader is designed to execute the query and return a
rowset in the form of an XmlReader object.

hth

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

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