SqlCommand

noun

say it: “ESS-kyoo-EL kuh-MAND” /ˌɛs kjuː ˈɛl kəˈmænd/

The ADO.NET class that holds one SQL statement and runs it on an open connection.

What is SqlCommand in C#?

SqlCommand — The ADO.NET object that holds one SQL statement and runs it on an open connection. ExecuteScalar returns one value, ExecuteReader returns rows, and ExecuteNonQuery runs an INSERT, UPDATE or DELETE.

using SqlCommand command = new("SELECT COUNT(*) FROM Products", connection);
int count = (int)command.ExecuteScalar();
Console.WriteLine(count); // 77

In a sentence

  • “I put the query and its @id parameter in a SqlCommand and called ExecuteReader.”

Level: Journeyman · More C# terms at this level

Updated