Tutorials ADO.NET Core Tutorial
SqlDataReader — Complete Guide
SqlDataReader — 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 8 of 100
SqlDataReader
Foundations → SQL & safety → Production → Projects
Foundations · 1 — Connections & CRUD · ~6 min · Module 1: ADO.NET Fundamentals
What is this?
SqlDataReader streams result rows forward-only — ReadAsync one row at a time.
Why should you care?
ShopNest ERP exports must not load millions of rows into a List.
See it live — copy this example
Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.
await using var reader = await cmd.ExecuteReaderAsync(ct);
var idOrd = reader.GetOrdinal("Id");
var totalOrd = reader.GetOrdinal("Total");
while (await reader.ReadAsync(ct))
{
Console.WriteLine($"{reader.GetInt32(idOrd)}:{reader.GetDecimal(totalOrd)}");
}
What happened?
- Cache ordinals outside the loop.
- Map to DTOs.
- Finish the reader before another command on the same connection (unless MARS).
Practice next
- Stream 1k+ rows.
- Compare memory vs DataTable.
- Map to OrderDto.
- Use IsDBNull before GetDecimal.
- yield return DTOs.
Remember
Stream rows. Low memory. Ordinals once.
ShopNest report stream
Nightly export uses SqlDataReader.
Outcome: Memory stays flat.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!