.NET track

ADO.NET Tutorial

Fast, direct SQL Server access from C#: connections, commands, readers, parameters, procedures, transactions and Dapper.

IntermediateExamples use Microsoft.Data.SqlClient on .NET 9 with SQL Server 2022.
0/32 complete
Topics
32
Full lessons
32
Est. hours
~6
Interview Qs
16

Overview

ADO.NET is the data access layer built into .NET. You open a connection, run SQL or stored procedures with a command, and read the results — with full control over every query that reaches the database.

Entity Framework Core, Dapper and every other .NET data library are built on top of ADO.NET. This track teaches the connected model (SqlConnection, SqlCommand, SqlDataReader), the disconnected model (DataSet, DataTable, SqlDataAdapter), and the production skills: parameters, transactions, async, bulk loading and clean repository design.

What you will learn

  • Connect to SQL Server and use connection pooling correctly
  • Run safe, parameterised queries and stored procedures
  • Read data with SqlDataReader and DataTable
  • Use transactions, async, bulk copy and the repository pattern

Prerequisites

You will get the most from this track if you already know:

Learning path

The recommended sequence, from beginner to advanced. Each stage builds on the one before.

  1. 1Getting Started · 6 topics · Beginner
    Introduction to ADO.NET · ADO.NET Architecture · Data Providers · Connection Strings · SqlConnection · Connection Pooling
  2. 2Executing Commands · 8 topics · Beginner → Intermediate
    SqlCommand · ExecuteNonQuery · ExecuteScalar · SqlDataReader · Parameterized Queries · SQL Injection Prevention · Stored Procedures · Output Parameters and Return Values
  3. 3Disconnected Data · 3 topics · Intermediate
    DataSet and DataTable · SqlDataAdapter · DataView
  4. 4Advanced · 7 topics · Intermediate → Advanced
    Transactions · Async Data Access · Multiple Result Sets · Handling NULL Values · Error Handling · SqlBulkCopy · Table-Valued Parameters
  5. 5Architecture · 5 topics · Advanced
    Configuration and Dependency Injection · Mapping Rows to Objects · Repository Pattern · Dapper · ADO.NET vs Entity Framework
  6. 6Practice · 3 topics · Advanced
    Performance Best Practices · Complete CRUD Project · Interview Questions

Complete topic list

32 topics
1

Getting Started

6 topics
  1. Introduction to ADO.NETBeginner5m
  2. ADO.NET ArchitectureBeginner5m
  3. Data ProvidersBeginner5m
  4. Connection StringsBeginner5m
  5. SqlConnectionBeginner5m
  6. Connection PoolingBeginner5m
2

Executing Commands

8 topics
  1. SqlCommandBeginner5m
  2. ExecuteNonQueryBeginner5m
  3. ExecuteScalarIntermediate5m
  4. SqlDataReaderIntermediate5m
  5. Parameterized QueriesIntermediate5m
  6. SQL Injection PreventionIntermediate5m
  7. Stored ProceduresIntermediate5m
  8. Output Parameters and Return ValuesIntermediate5m
3

Disconnected Data

3 topics
  1. DataSet and DataTableIntermediate5m
  2. SqlDataAdapterIntermediate5m
  3. DataViewIntermediate5m
4

Advanced

7 topics
  1. TransactionsIntermediate5m
  2. Async Data AccessIntermediate5m
  3. Multiple Result SetsIntermediate5m
  4. Handling NULL ValuesIntermediate5m
  5. Error HandlingIntermediate5m
  6. SqlBulkCopyAdvanced5m
  7. Table-Valued ParametersAdvanced5m
5

Architecture

5 topics
  1. Configuration and Dependency InjectionAdvanced5m
  2. Mapping Rows to ObjectsAdvanced5m
  3. Repository PatternAdvanced5m
  4. DapperAdvanced5m
  5. ADO.NET vs Entity FrameworkAdvanced5m
6

Practice

3 topics
  1. Performance Best PracticesAdvanced5m
  2. Complete CRUD ProjectAdvanced5m
  3. Interview QuestionsAdvanced15m

Code example

A taste of the track, from Introduction to ADO.NET.

C#Program.cs Illustrative
// dotnet new console -n ShopData && cd ShopData
// dotnet add package Microsoft.Data.SqlClient
using Microsoft.Data.SqlClient;


const string cs = "Server=localhost;Database=ShopDB;Integrated Security=True;TrustServerCertificate=True;";


using var conn = new SqlConnection(cs);          // 1. connection
conn.Open();


using var cmd = new SqlCommand("SELECT Id, Name, Price FROM Products ORDER BY Id", conn);   // 2. command
using var reader = cmd.ExecuteReader();          // 3. execute


while (reader.Read())                            // 4. read row by row
{
    Console.WriteLine(
quot;
{reader.GetInt32(0)}. {reader.GetString(1)} - ₹{reader.GetDecimal(2)}");
} // 5. using closes reader, command and connection automatically
Expected output
1. Laptop - ₹55000.00
2. Mouse - ₹1400.00
3. Keyboard - ₹2200.00

Practice exercises

Show all 31 exercises
SqlCommand

Use one command in a loop to set Stock = 0 for product Ids 4, 5 and 6.

ExecuteNonQuery

Write an UPDATE that changes a product’s price and returns false when the product does not exist.

ExecuteScalar

Return the name of the most expensive product, or "none" if the table is empty.

SqlDataReader

Read Id and Name of products with Price above a given amount into a List<(int, string)>.

Parameterized Queries

Write the parameter for a VARCHAR(20) column called Sku without causing an NVARCHAR conversion.

SQL Injection Prevention

Fix this code: new SqlCommand("DELETE FROM Products WHERE Id = " + id, conn).

Stored Procedures

Call dbo.GetProductsByCategory for category 2 with @MinStock = 10.

Output Parameters and Return Values

Add an output parameter @NewStock INT to read the remaining stock after the order.

DataSet and DataTable

Compute the total price of all non-deleted rows using row.Field<decimal>.

SqlDataAdapter

Load only products in category 1 using a parameter in the adapter’s SelectCommand.

DataView

Show only modified rows in a view.

Transactions

Rewrite the order with TransactionScope for async code.

Async Data Access

Add a 5-second timeout to the query using a CancellationTokenSource linked to the request token.

Multiple Result Sets

Write a loop that prints the number of rows in each result set, whatever the count of sets.

Handling NULL Values

Read a nullable DECIMAL column DiscountPrice into a decimal? using the helper.

Error Handling

Add a catch that turns error 547 into the message "This category is still used by products" when deleting a category.

SqlBulkCopy

Bulk copy into dbo.ProductsStaging instead and then insert only new names into Products.

Table-Valued Parameters

Write a stored procedure dbo.DeleteProducts that accepts @Ids dbo.IdList and deletes those products.

Configuration and Dependency Injection

Set the production connection string with an environment variable.

Mapping Rows to Objects

Write a static Map method for ProductDto from a reader positioned on a row with Id, Name, Price.

Repository Pattern

Add a SearchAsync(string term) method to the interface and implementation.

Dapper

Update a product’s price with Dapper and return whether a row changed.

ADO.NET vs Entity Framework

Choose a tool for: (a) importing 500k rows nightly, (b) a typical admin CRUD screen, (c) a complex reporting query.

Performance Best Practices

Which index would help ORDER BY Name with OFFSET/FETCH on Products?

Complete CRUD Project

Add a GET /api/products/search?q= endpoint using the SearchAsync method from the repository lesson.

Common interview questions

Frequently asked questions

Is ADO.NET still used?
Yes. It is the foundation of every .NET data library, and many production systems use it directly (or through Dapper) for stored procedures, reporting and performance-critical queries.
System.Data.SqlClient or Microsoft.Data.SqlClient?
Use Microsoft.Data.SqlClient for all new code. System.Data.SqlClient is deprecated and only receives security fixes.
Should I learn ADO.NET or Entity Framework first?
Learning ADO.NET first helps you understand what EF Core does for you — connections, SQL, parameters and mapping — and makes debugging EF much easier.