This documentation is archived and is not being maintained.

OdbcCommand.Parameters Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Gets the OdbcParameterCollection.

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

Property Value

The parameters of the SQL statement or stored procedure. The default is an empty collection.


When CommandType is set to Text, the .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand. In either of these cases, use the question mark (?) placeholder. For example:

SELECT * FROM Customers WHERE CustomerID = ?

The order in which OdbcParameter objects are added to the OdbcParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text. For more information, see Using Stored Procedures with a Command.

Note   If the parameters in the collection do not match the requirements of the query to be executed, an error may result.


[Visual Basic, C#, C++] The following example creates an OdbcCommand and displays its parameters. To accomplish this, the method is passed an OdbcConnection, a query string that is an SQL SELECT statement, and an array of OdbcParameter objects.

[Visual Basic] 
Public Sub CreateMyOdbcCommand(myConnection As OdbcConnection, _
mySelectQuery As String, myParamArray() As OdbcParameter)
    Dim myCommand As New OdbcCommand(mySelectQuery, myConnection)
    myCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers WHERE Country = ? AND City = ?"
    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 CreateMyOdbcCommand(OdbcConnection myConnection,
string mySelectQuery, OdbcParameter[] myParamArray) {
   OdbcCommand myCommand = new OdbcCommand(mySelectQuery, myConnection);
   myCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers WHERE Country = ? AND 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 CreateMyOdbcCommand(OdbcConnection* myConnection, String* mySelectQuery, OdbcParameter* myParamArray[])
        OdbcCommand* myCommand = new OdbcCommand(mySelectQuery, myConnection);
        myCommand->CommandText = S"SELECT CustomerID, CompanyName FROM Customers WHERE Country = ? AND City = ?";
        for (int j=0; j<myParamArray->Length; 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

See Also

OdbcCommand Class | OdbcCommand Members | System.Data.Odbc Namespace | OdbcParameter