Export (0) Print
Expand All

OleDbCommand.Parameters Property

Gets the OleDbParameterCollection.

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

Property Value

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


The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL Statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used. For example:

SELECT * FROM Customers WHERE CustomerID = ?

As a result, the order in which OleDbParameter objects are added to the OleDbParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text.

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

For more information, see Using Stored Procedures with a Command.


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

[Visual Basic] 
Public Sub CreateMyOleDbCommand(myConnection As OleDbConnection, _
mySelectQuery As String, myParamArray() As OleDbParameter)
    Dim myCommand As New OleDbCommand(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 CreateMyOleDbCommand(OleDbConnection myConnection,
string mySelectQuery, OleDbParameter[] myParamArray) {
   OleDbCommand myCommand = new OleDbCommand(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 CreateMyOleDbCommand(OleDbConnection* myConnection,
 String* mySelectQuery, OleDbParameter* myParamArray[]) {
    OleDbCommand* myCommand = new OleDbCommand(mySelectQuery, myConnection);
    myCommand->CommandText = S"SELECT CustomerID, CompanyName FROM Customers WHERE Country = ? AND 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

See Also

OleDbCommand Class | OleDbCommand Members | System.Data.OleDb Namespace | OleDbParameter

© 2014 Microsoft