Tutorials ADO.NET Core Tutorial

Select Operations — Complete Guide

Select Operations — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of ADO.NET Core Tutorial on Toolliyo Academy.

On this page

ADO.NET Core Tutorial · Lesson 12 of 100

Select Operations

FoundationsSQL & safetyProductionProjects

Foundations · 1 — Connections & CRUD · ~6 min · Module 2: CRUD Operations

What is this?

SELECT reads rows. Use readers for lists, ExecuteScalarAsync for one value, narrow column lists always.

Why should you care?

Most ShopNest endpoints are reads — indexes and projections decide latency.

See it live — copy this example

Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.

cmd.CommandText = @"
SELECT Id, Total, Status FROM Orders
WHERE CustomerId = @CustomerId
ORDER BY Id DESC
OFFSET @Skip ROWS FETCH NEXT @Take ROWS ONLY";
cmd.Parameters.Add("@CustomerId", SqlDbType.Int).Value = 7;
cmd.Parameters.Add("@Skip", SqlDbType.Int).Value = 0;
cmd.Parameters.Add("@Take", SqlDbType.Int).Value = 20;

What happened?

  • Project only needed columns.
  • Paginate.
  • Index CustomerId for this pattern.

Practice next

  1. Run in SSMS with plan.
  2. Same query via reader.
  3. Avoid SELECT *.
  4. Change Take to 5.
  5. Select COUNT(*) with scalar.

Remember

Narrow selects. Paginate. Index filters.

ShopNest order history

Account page lists last 20 orders.

Outcome: Stable p95 with an index on CustomerId.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Mid PDF Detailed
Bind the data to the GridView. Example: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection connection = new SqlConnection(connectionString); SqlDataAdapter adapter = new SqlDataAdapter("SELECT CustomerID, CustomerName FROM Customers", connection); DataTable dataTable = new DataTable();
Short answer: dapter.Fill(dataTable); GridView1.DataSource = dataTable; GridView1.DataBind(); } } Here, GridView1 is bound to the data returned from the SQL query (SELECT CustomerID, CustomerName FROM Customers), and the…
Mid PDF Detailed
It uses SQL commands to retrieve and update data. Example: SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Customers", connection); DataSet dataset = new DataSet();
Short answer: dapter.Fill(dataset, "Customers"); // Populates the DataSet with data from the "Customers" table dapter.Fill(dataset, "Customers"); // Populates the DataSet with data from the…
Mid PDF Detailed
Use the DataAdapter's Update() method to push the changes back to the database. Example: SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Customers", connection); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adapter); // Automatically generates insert, update, delete commands DataSet dataset = new DataSet();
Short answer: dapter.Fill(dataset, "Customers"); // Modify data in the DataSet dataset.Tables["Customers"].Rows[0]["CustomerName"] = "New Name"; // Update the database with the mod…
Mid PDF Detailed
Use Asynchronous Operations: For very large datasets, consider performing?
Short answer: database operations asynchronously to avoid blocking the main thread and keep the application responsive. Real-world example (ShopNest) For large order exports, ShopNest uses SqlDataReader (forward-only, fa…
Mid PDF Detailed
Call the Update method on the DataAdapter to sync changes. Example: // Assuming you already have a populated DataTable DataTable table = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Customers", connection); // Set commands for Insert, Update, and Delete
Short answer: dapter.UpdateCommand = new SqlCommand("UPDATE Customers SET CustomerName = @CustomerName WHERE CustomerID = @CustomerID", connection); dapter.UpdateCommand.Parameters.Add("@CustomerName"…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

ADO.NET Core Tutorial
Course syllabus

ADO.NET Core Tutorial

Module 1: ADO.NET Fundamentals
Module 2: CRUD Operations
Module 3: Stored Procedures
Module 4: Transactions and Error Handling
Module 5: Performance Optimization
Module 6: ASP.NET Core Integration
Module 7: Advanced Enterprise Topics
Module 8: Testing and Debugging
Module 9: Cloud and DevOps
Module 10: Real-World Enterprise Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details