ADO.NET

Overview

ADO.NET provides a rich set of components for building data-driven applications on the Windows platform. It enables you to connect to relational databases, execute commands, and retrieve results efficiently.

Key Concepts

Getting Started

Install the System.Data.SqlClient NuGet package or use the built‑in library in .NET 6+.

dotnet add package System.Data.SqlClient

Sample code:

using System.Data.SqlClient;

string cs = "Server=.;Database=AdventureWorks;Trusted_Connection=True;";
using var conn = new SqlConnection(cs);
await conn.OpenAsync();
using var cmd = new SqlCommand("SELECT TOP 10 * FROM Production.Product", conn);
using var reader = await cmd.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
    Console.WriteLine($"{reader["ProductID"]}: {reader["Name"]}");
}

Best Practices

Resources

Official ADO.NET Documentation

GitHub – .NET SqlClient