OleDbCommand.Parameters Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the OleDbParameterCollection.
public:
property System::Data::OleDb::OleDbParameterCollection ^ Parameters { System::Data::OleDb::OleDbParameterCollection ^ get(); };
public System.Data.OleDb.OleDbParameterCollection Parameters { get; }
[System.Data.DataSysDescription("DbCommand_Parameters")]
public System.Data.OleDb.OleDbParameterCollection Parameters { get; }
member this.Parameters : System.Data.OleDb.OleDbParameterCollection
[<System.Data.DataSysDescription("DbCommand_Parameters")>]
member this.Parameters : System.Data.OleDb.OleDbParameterCollection
Public ReadOnly Property Parameters As OleDbParameterCollection
The parameters of the SQL statement or stored procedure. The default is an empty collection.
- Attributes
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.
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);
}
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
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.
Megjegyzés
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.
Termék | Verziók |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
.NET-visszajelzés
A(z) .NET egy nyílt forráskód projekt. Visszajelzés adásához válasszon egy hivatkozást: