Multiple choice technology programming languages

You decide to use named parameters in a SqlCommand object in order to execute SQL queries on a database. You have a parameter named “CustomerName”. How do you refer to it within the SQL query text in the SqlCommand object?

  1. “?CustomerName”

  2. “@CustomerName”

  3. “%CustomerName”

  4. “#CustomerName”

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In ADO.NET SQL parameters, the @ prefix is the standard notation for named parameters in SqlCommand objects. You write "@CustomerName" in the SQL query and then add the parameter value to the Parameters collection. The ? prefix is used by some other database systems (like ODBC), % is typically for wildcards, and # is used in some SQL dialects for temporary tables or comments.

AI explanation

To refer to a named parameter within the SQL query text in a SqlCommand object, you would use the "@" symbol followed by the parameter name.

So the correct way to refer to the parameter named "CustomerName" in the SQL query text would be:

B. "@CustomerName"