Junior
From PDF
ADO.NET
ADO.NET
What is the difference between ExecuteNonQuery, ExecuteReader, and ExecuteScalar?
Short answer: ExecuteNonQuery: Executes SQL commands that do not return data (e.g., INSERT, UPDATE, DELETE).
Example code
command.ExecuteNonQuery(); (used to insert a record). ExecuteReader: Executes SQL commands that return rows (e.g., SELECT queries). It returns a DataReader. Example: command.ExecuteReader(); (used to select records). ExecuteScalar: Executes SQL commands and returns a single value (e.g., a single cell of data). Example: command.ExecuteScalar(); (used for retrieving the count or aggregate values).
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png