Tutorials ADO.NET Core Tutorial
SqlCommand — Complete Guide
SqlCommand — 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 7 of 100
SqlCommand
Foundations → SQL & safety → Production → Projects
Foundations · 1 — Connections & CRUD · ~6 min · Module 1: ADO.NET Fundamentals
What is this?
SqlCommand holds SQL or a procedure name, parameters, timeout, and the connection — then Execute* runs it.
Why should you care?
Every ShopNest insert/select/update/delete goes through SqlCommand.
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 cmd = new SqlCommand(@"
INSERT INTO Orders (CustomerId, Total, Status)
VALUES (@CustomerId, @Total, @Status);", conn);
cmd.Parameters.Add("@CustomerId", SqlDbType.Int).Value = 7;
cmd.Parameters.Add("@Total", SqlDbType.Decimal).Value = 4999m;
cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 20).Value = "Pending";
var rows = await cmd.ExecuteNonQueryAsync(ct);
Console.WriteLine(rows);
What happened?
- Typed parameters.
- ExecuteNonQueryAsync for DML.
- CommandTimeout defaults to 30s.
Practice next
- Insert one order.
- Print rows affected.
- Raise timeout only for reports.
- Add CommandTimeout = 5 and watch.
- Use ExecuteScalar for COUNT(*).
Remember
SQL + parameters. Right Execute*. No string concat.
ShopNest insert command
Checkout writes Orders via SqlCommand.
Outcome: Parameters keep inserts safe.
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!