IDbCommand.Parameters Property

Definition

C#
public System.Data.IDataParameterCollection Parameters { get; }

Property Value

The parameters of the SQL statement or stored procedure.

Examples

The following example creates an instance of the derived class, SqlCommand, and displays its parameters. In the example, the application passes a SqlConnection, a query string that is a Transact-SQL SELECT statement, and an array of SqlParameter objects.

C#
public void CreateSqlCommand(SqlConnection myConnection,
    string queryString, SqlParameter[] paramArray)
{
    SqlCommand command = new SqlCommand(queryString, myConnection);
    command.CommandText =
        "SELECT CustomerID, CompanyName FROM Customers "
        + "WHERE Country = @Country AND City = @City";
    command.Parameters.AddRange(paramArray);

    string message = "";
    for (int i = 0; i < command.Parameters.Count; i++)
    {
        message += command.Parameters[i].ToString() + "\n";
    }
    Console.WriteLine(message);
}

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also