IDbCommand.Parameters 属性

定义

public:
 property System::Data::IDataParameterCollection ^ Parameters { System::Data::IDataParameterCollection ^ get(); };
public System.Data.IDataParameterCollection Parameters { get; }
member this.Parameters : System.Data.IDataParameterCollection
Public ReadOnly Property Parameters As IDataParameterCollection

属性值

SQL 语句或存储过程的参数。The parameters of the SQL statement or stored procedure.

示例

下面的示例创建派生类的实例,SqlCommand,并显示其参数。The following example creates an instance of the derived class, SqlCommand, and displays its parameters. 在此示例中,应用程序传递一个 SqlConnection、一个查询字符串(即 Transact-sql SELECT 语句)和一个 SqlParameter 对象的数组。In the example, the application passes a SqlConnection, a query string that is a Transact-SQL SELECT statement, and an array of SqlParameter objects.

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);
}
Public Sub CreateSqlCommand(ByVal connection As SqlConnection, _
ByVal queryString As String, ByVal params() As SqlParameter)

    Dim command As New SqlCommand(queryString, connection)
    command.CommandText = _
       "SELECT CustomerID, CompanyName FROM Customers " _
       & "WHERE Country = @Country AND City = @City"
    command.UpdatedRowSource = UpdateRowSource.Both
    command.Parameters.AddRange(params)

    Dim message As String = ""
    For i As Integer = 0 To command.Parameters.Count - 1
        message += command.Parameters(i).ToString() & ControlChars.Cr
    Next 

    Console.WriteLine(message)
End Sub

适用于

另请参阅