IDbCommand.Parameters Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient le IDataParameterCollection.
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
Valeur de propriété
Paramètres de l’instruction SQL ou de la procédure stockée.
Exemples
L’exemple suivant crée une instance de la classe dérivée et SqlCommandaffiche ses paramètres. Dans l’exemple, l’application transmet une SqlConnection, une chaîne de requête qui est une instruction SELECT Transact-SQL et un tableau d’objets 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