Menu

Core objects and the connected model — ADO.NET
📰

Core objects and the connected model — ADO.NET

DEV Community: dotnet·DIVAKAR UPADHYAY·4 days ago
#PA3JBesE
#devtodotnet#devto#dev#reader#await
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.