Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
OleDbCommand Class
 Parameters Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
OleDbCommand..::.Parameters Property

Namespace:  System.Data.OleDb
Assembly:  System.Data (in System.Data.dll)
Visual Basic (Declaration)
Public ReadOnly Property Parameters As OleDbParameterCollection
Visual Basic (Usage)
Dim instance As OleDbCommand
Dim value As OleDbParameterCollection

value = instance.Parameters
C#
public OleDbParameterCollection Parameters { get; }
Visual C++
public:
property OleDbParameterCollection^ Parameters {
    OleDbParameterCollection^ get ();
}
JScript
public function get Parameters () : OleDbParameterCollection

Property Value

Type: System.Data.OleDb..::.OleDbParameterCollection
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 = ?

Therefore, 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.

NoteNote:

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 Configuring Parameters and Parameter Data Types (ADO.NET).

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

Visual Basic
Public Sub CreateMyOleDbCommand(connection As OleDbConnection, _
   queryString As String, parameters() As OleDbParameter)

    Dim command As New OleDbCommand(queryString, connection)
    command.CommandText = _
       "SELECT CustomerID, CompanyName FROM Customers WHERE Country = ? AND City = ?"
    command.Parameters.Add(parameters)

    Dim j As Integer
    For j = 0 To command.Parameters.Count - 1
       command.Parameters.Add(parameters(j))
    Next j

    Dim message As String = ""
    Dim i As Integer
    For i = 0 To command.Parameters.Count - 1
        message += command.Parameters(i).ToString() + ControlChars.Cr
    Next i
    Console.WriteLine(message)
End Sub

C#
public void CreateMyOleDbCommand(OleDbConnection connection,
    string queryString, OleDbParameter[] parameters) 
{
    OleDbCommand command = new OleDbCommand(queryString, connection);
    command.CommandText = 
        "SELECT CustomerID, CompanyName FROM Customers WHERE Country = ? AND City = ?";
    command.Parameters.Add(parameters);

    for (int j=0; j<parameters.Length; j++)
    {
        command.Parameters.Add(parameters[j]) ;
    }

    string message = "";
    for (int i = 0; i < command.Parameters.Count; i++) 
    {
        message += command.Parameters[i].ToString() + "\n";
    }
    Console.WriteLine(message);
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker