asp.net.ph

OleDbCommand.Parameters Property

System.Data.OleDb Namespace   OleDbCommand Class


Returns the OleDbParameterCollection.

Syntax


Script [ OleDbParameterCollection variable = ] OleDbCommand.Parameters

Property Value


variable The parameters of the SQL statement or stored procedure.

The property is read/write with no default value.

Remarks

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.

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.

Example

The following example illustrates using the Parameters collection.

void ParametersDemo ( OleDbConnection myConn,
      string query, OleDbParameter [ ] myParamArray ) {
   OleDbCommand myCommand = new OleDbCommand ( query, myConn );
   myCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers " +
      "WHERE Country = @Country AND City = @City";

   myCommand.Parameters.Add ( myParamArray );

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

   string myMessage = "";
   for ( int i = 0; i < myCommand.Parameters.Count; i++ ) {
      myMessage += myCommand.Parameters [ ].ToString ( ) + "<br>";
   }
   Response.Write ( myMessage );
}
  C# VB

See Also

OleDbCommand Members   OleDbParameter Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph