difference between connected oriented and Dis_connected oriented with ado.net example?
How to use ExecuteReader(), ExecuteNonquery(), ExecuteScaler() with example?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Manikandan MurugesanRank #300 · 8.4K reputationPosted Jul 19, 2017, 7:51 AM EDT
DataReader is connected architecture since it keeps conneection open untill all records are fetched
DataSet is disconnected architecture gets all records at once and closes connection and are available even after connection is closed
ExecuteScalaris typically used when your query returns a single value. If it returns more, then the result is the first column of the first row. An example might beSELECT @@IDENTITY AS 'Identity'.ExecuteReaderis used for any result set with multiple rows/columns (e.g.,SELECT col1, col2 from sometable).ExecuteNonQueryis typically used for SQL statements without results (e.g., UPDATE, INSERT, etc.).ExecuteScalar() only returns the value from the first column of the first row of your query.
ExecuteReader() returns an object that can iterate over the entire result set while only keeping one record in memory at a time.
ExecuteNonQuery() does not return data at all: only the number of rows affected by an insert, update, or delete.
Additionally, you can look at the DbDataAdapter type, which includes a Fill() method that allows you to download the entire resultset into a DataTable or DataSet object, as well as a number of other abilities.