Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the Microsoft Certified Solutions Developer Certification Test. Use multiple choice quizzes with hints and explanations to boost your readiness. Excel on your test!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


To execute a command against a database, which class is used in C#?

  1. SqlCommand

  2. DbCommand

  3. SqlDataAdapter

  4. SqlDataReader

The correct answer is: SqlCommand

The use of the SqlCommand class in C# is essential for executing SQL statements against a SQL Server database. This class provides a straightforward way to run commands such as queries or stored procedures, and it is specifically designed to work with the SQL Server database through the System.Data.SqlClient namespace. SqlCommand allows developers to set up and send commands to a SQL Server instance, managing parameters, command text, and execution options effectively. When you create an instance of SqlCommand, you typically specify the connection to the database, the SQL command to be executed, and any other configurations, such as command type and parameters. While DbCommand is a more abstract class that can be used with different types of databases, SqlCommand is specifically optimized for SQL Server, which is often the preferred choice for developers working in environments that predominantly utilize this database. The other options like SqlDataAdapter and SqlDataReader serve different purposes: SqlDataAdapter is used for filling a DataSet and managing updates to the database, while SqlDataReader is used for reading data in a forward-only, read-only manner from the database. Neither of these classes is designed specifically for executing commands against a database, making SqlCommand the most appropriate choice for this task.