Difference ExecuteNonQuery vs ExecuteScalar vs ExecuteReader in asp.net

In Previous article we shared resourceful article for ExecuteNonQuery() example, ExecuteScalar() Example and ExecuteReader() example. Now we comes with very important question asked by every interviewer "what is Difference between ExecuteNonQuery, ExecuteScalar and ExecuteReader".

ExecuteNonQuery() is use when we use T-SQL Statement in our system like insert, update and delete. ExecuteNonQuery() will return no of affected rows in database. To get proper result we must declare it after T-SQL Statement execution complete.
You can read ExecuteNonQuery with example in asp.net for more detail

ExecuteScalar() method of SqlCommand Class. ExecuteScalar() method will return only First Column First Row (you can also take it as first row first column , both are same) value from whole datatable.
You can read ExecuteScalar with example in asp.net for more detail
ExecuteReader() method will return set of row on execution of SQL Statement.When SQLCommand SQLCommand.ExecuteReader() execute it will initialize SQLDataReader object.  SQLDataReader is forwardonly and readonly.
You can read ExecuteReader with example in asp.net for more detail


Popular posts from this blog

12 opensource and free asp.net MVC gridview contols

Scheduling background jobs using Hangfire in ASP.NET Core