Parameters Property

IDbCommand.Parameters Property

Gets the IDataParameterCollection.

[Visual Basic]
ReadOnly Property Parameters As IDataParameterCollection
IDataParameterCollection Parameters {get;}
__property IDataParameterCollection* get_Parameters();
function get Parameters() : IDataParameterCollection;

Property Value

The parameters of the SQL statement or stored procedure.


[Visual Basic, C#, C++] 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.

[Visual Basic] 
Public Sub CreateMySqlCommand(myConnection As SqlConnection, _
mySelectQuery As String, myParamArray() As SqlParameter)
    Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
    myCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers WHERE Country = @Country AND City = @City"
    myCommand.UpdatedRowSource = UpdateRowSource.Both
    Dim j As Integer
    For j = 0 To myCommand.Parameters.Count - 1
    Next j
    Dim myMessage As String = ""
    Dim i As Integer
    For i = 0 To myCommand.Parameters.Count - 1
        myMessage += myCommand.Parameters(i).ToString() & ControlChars.Cr
    Next i
End Sub

public void CreateMySqlCommand(SqlConnection myConnection,
string mySelectQuery, SqlParameter[] myParamArray) {
   SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
   myCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers WHERE Country = @Country AND City = @City";    
   for (int j=0; j<myParamArray.Length; j++)
      myCommand.Parameters.Add(myParamArray[j]) ;
   string myMessage = "";
   for (int i = 0; i < myCommand.Parameters.Count; i++) 
      myMessage += myCommand.Parameters[i].ToString() + "\n";

 void CreateMySqlCommand(SqlConnection* myConnection,
 String* mySelectQuery, SqlParameter* myParamArray[]) {
    SqlCommand* myCommand = new SqlCommand(mySelectQuery, myConnection);
    myCommand->CommandText = S"SELECT CustomerID, CompanyName FROM Customers WHERE Country = @Country AND City = @City";    
    for (int j=0; j<myParamArray->Length; j++)
       myCommand->Parameters->Add(myParamArray[j]) ;
    String* myMessage = S"";
    for (int i = 0; i < myCommand->Parameters->Count; i++) 
       myMessage = String::Concat( myMessage, myCommand->Parameters->Item[i], S"\n" );

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

IDbCommand Interface | IDbCommand Members | System.Data Namespace | IDataParameter

© 2015 Microsoft