How would you retrieve a single row or column of data using ADO.NET?
Short answer: To retrieve a single row or column of data, you can use a SqlCommand and either execute it with ExecuteScalar (for single column data) or ExecuteReader (for a single row).
Explain a bit more
Using ExecuteScalar (for a single column value, like an aggregate): SqlCommand command = new SqlCommand("SELECT CustomerName FROM Customers WHERE CustomerID = @CustomerID", connection); command.Parameters.AddWithValue("@CustomerID", 1); connection.Open(); string customerName = (string)command.ExecuteScalar(); Console.WriteLine("Customer Name: " + customerName); connection.Close();
Real-world example (ShopNest)
ShopNest’s reporting job still uses ADO.NET for a heavy SQL query where raw performance and stored procedures matter more than EF convenience.
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