IDbCommand.Parameters 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
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 陳述式或預存程序的參數。
範例
下列範例會建立衍生類別 SqlCommand的實例,並顯示其參數。 在此範例中,應用程式會傳遞、 SqlConnection是 Transact-SQL SELECT 語句的查詢字串,以及 物件的陣列 SqlParameter 。
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