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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manikandan MurugesanPosted Jul 19, 2017, 11:51 AM
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.