Lesson 1 of 9 in the free ADO.NET — Connected & Disconnected Data Access course on DevLadder.
Object Role
SqlConnection Connection to the DB (pooled)
SqlCommand SQL statement or stored procedure
SqlParameter Typed parameter value — prevents SQL injection
SqlDataReader Fast, forward-only, read-only stream of rows
SqlDataAdapter Bridge between DB and DataSet
DataSet / DataTable In-memory relational data
SqlTransaction Groups commands atomically
SqlBulkCopy High-speed bulk insert
const string cs = "Server=.;Database=Shop;Integrated Security=True;TrustServerCertificate=True" ;
await using var conn = new SqlConnection ( cs ); await conn . OpenAsync ( ct );
await using var cmd = new SqlCommand ( "SELECT Id, Name, Price FROM Products WHERE CategoryId = @cat" , conn ); cmd . Parameters . Add ( "@cat" , SqlDbType . Int ). Value = categoryId ;
await using var reader = await cmd . ExecuteReaderAsync ( ct ); var list = new List < Product >(); while ( await reader . ReadAsync ( ct )) { list .…