OleDbParameterCollection.Add Method

Definition

Overloads

Add(OleDbParameter)

Adds the specified OleDbParameter to the OleDbParameterCollection.

Add(Object)

Adds the specified OleDbParameter object to the OleDbParameterCollection.

Add(String, OleDbType)

Adds an OleDbParameter to the OleDbParameterCollection, given the parameter name and data type.

Add(String, Object)

Adds an OleDbParameter to the OleDbParameterCollection given the parameter name and value.

Add(String, OleDbType, Int32)

Adds an OleDbParameter to the OleDbParameterCollection given the parameter name, data type, and column length.

Add(String, OleDbType, Int32, String)

Adds an OleDbParameter to the OleDbParameterCollection given the parameter name, data type, column length, and source column name.

Add(OleDbParameter)

Adds the specified OleDbParameter to the OleDbParameterCollection.

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::Data::OleDb::OleDbParameter ^ value);
public System.Data.OleDb.OleDbParameter Add (System.Data.OleDb.OleDbParameter value);
override this.Add : System.Data.OleDb.OleDbParameter -> System.Data.OleDb.OleDbParameter
Public Function Add (value As OleDbParameter) As OleDbParameter

Parameters

value
OleDbParameter

The OleDbParameter to add to the collection.

Returns

The index of the new OleDbParameter object.

Exceptions

The OleDbParameter specified in the value parameter is already added to this or another OleDbParameterCollection.

The value parameter is null.

Examples

The following example creates an OleDbParameterCollection and adds an OleDbParameter.

public void CreateParameters() 
{
    OleDbCommand command = new OleDbCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OleDbParameterCollection paramCollection = command.Parameters;
    OleDbParameter myParm = paramCollection.Add(
        new OleDbParameter("CustomerID", OleDbType.VarChar));
}
Public Sub CreateParameters(connection As OleDbConnection)
  Dim command As New OleDbCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OleDbParameterCollection = command.Parameters
  Dim myParm As OleDbParameter = paramCollection.Add( _
    New OleDbParameter("CustomerID", OleDbType.VarChar))
End Sub 

See also

Add(Object)

Adds the specified OleDbParameter object to the OleDbParameterCollection.

public:
 virtual int Add(System::Object ^ value);
public int Add (object value);
override this.Add : obj -> int
Public Function Add (value As Object) As Integer

Parameters

value
Object

A Object.

Returns

The index of the new OleDbParameter object in the collection.

See also

Add(String, OleDbType)

Adds an OleDbParameter to the OleDbParameterCollection, given the parameter name and data type.

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::String ^ parameterName, System::Data::OleDb::OleDbType oleDbType);
public System.Data.OleDb.OleDbParameter Add (string parameterName, System.Data.OleDb.OleDbType oleDbType);
override this.Add : string * System.Data.OleDb.OleDbType -> System.Data.OleDb.OleDbParameter

Parameters

parameterName
String

The name of the parameter.

oleDbType
OleDbType

One of the OleDbType values.

Returns

The index of the new OleDbParameter object.

Examples

The following example creates an OleDbParameterCollection and adds an OleDbParameter.

public void CreateParameters() 
{
    OleDbCommand command = new OleDbCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OleDbParameterCollection paramCollection = command.Parameters;
    OleDbParameter myParm = paramCollection.Add(
        "CustomerID", OleDbType.VarChar);
}
Public Sub CreateParameters(connection As OleDbConnection)
  Dim command As New OleDbCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OleDbParameterCollection = command.Parameters
  Dim myParm As OleDbParameter = paramCollection.Add( _
    "CustomerID", OleDbType.VarChar)
End Sub 

See also

Add(String, Object)

Warning

This API is now obsolete.

Adds an OleDbParameter to the OleDbParameterCollection given the parameter name and value.

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::String ^ parameterName, System::Object ^ value);
[System.Obsolete("Add(String parameterName, Object value) has been deprecated.  Use AddWithValue(String parameterName, Object value).  https://go.microsoft.com/fwlink/?linkid=14202", false)]
public System.Data.OleDb.OleDbParameter Add (string parameterName, object value);
override this.Add : string * obj -> System.Data.OleDb.OleDbParameter
Public Function Add (parameterName As String, value As Object) As OleDbParameter

Parameters

parameterName
String

The name of the parameter.

value
Object

The Value of the OleDbParameter to add to the collection.

Returns

The index of the new OleDbParameter object.

Attributes

Exceptions

The value parameter is not an OleDbParameter.

Remarks

Use caution when using this overload of the Add method to specify integer parameter values. Because this overload takes a value of type Object, you must convert the value to an Object type when the value is zero, as the following C# example demonstrates.

parameters.Add("@pname", Convert.ToInt32(0));  

If you do not perform this conversion, the compiler will assume you are attempting to call the Add overload.

See also

Add(String, OleDbType, Int32)

Adds an OleDbParameter to the OleDbParameterCollection given the parameter name, data type, and column length.

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::String ^ parameterName, System::Data::OleDb::OleDbType oleDbType, int size);
public System.Data.OleDb.OleDbParameter Add (string parameterName, System.Data.OleDb.OleDbType oleDbType, int size);
override this.Add : string * System.Data.OleDb.OleDbType * int -> System.Data.OleDb.OleDbParameter

Parameters

parameterName
String

The name of the parameter.

oleDbType
OleDbType

One of the OleDbType values.

size
Int32

The length of the column.

Returns

The index of the new OleDbParameter object.

Examples

The following example creates an OleDbParameterCollection, adds an instance of OleDbParameter to the collection, and returns a reference to the new OleDbParameter.

public void CreateParameters(OleDbConnection connection) 
{
    OleDbCommand command = new OleDbCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OleDbParameterCollection paramCollection = command.Parameters;
    OleDbParameter parameter = paramCollection.Add(
        "CustomerID", OleDbType.VarChar, 5);
}
Public Sub CreateParameters(connection As OleDbConnection)
  Dim command As New OleDbCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OleDbParameterCollection = command.Parameters
  Dim parameter As OleDbParameter = paramCollection.Add( _
    "CustomerID", OleDbType.VarChar, 5)
End Sub

See also

Add(String, OleDbType, Int32, String)

Adds an OleDbParameter to the OleDbParameterCollection given the parameter name, data type, column length, and source column name.

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::String ^ parameterName, System::Data::OleDb::OleDbType oleDbType, int size, System::String ^ sourceColumn);
public System.Data.OleDb.OleDbParameter Add (string parameterName, System.Data.OleDb.OleDbType oleDbType, int size, string sourceColumn);
override this.Add : string * System.Data.OleDb.OleDbType * int * string -> System.Data.OleDb.OleDbParameter

Parameters

parameterName
String

The name of the parameter.

oleDbType
OleDbType

One of the OleDbType values.

size
Int32

The length of the column.

sourceColumn
String

The name of the source column.

Returns

The index of the new OleDbParameter object.

Examples

The following example creates an OleDbParameterCollection, adds an instance of OleDbParameter to the collection, and returns a reference to the new OleDbParameter.

public void CreateParameters(OleDbConnection connection) 
{
    OleDbCommand command = new OleDbCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OleDbParameterCollection paramCollection = command.Parameters;
    OleDbParameter parameter = paramCollection.Add(
        "CustomerID", OleDbType.VarChar, 5, "CustomerID");
}
Public Sub CreateParameters(connection As OleDbConnection)
  Dim command As New OleDbCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OleDbParameterCollection = command.Parameters
  Dim parameter As OleDbParameter = paramCollection.Add( _
    "CustomerID", OleDbType.VarChar, 5, "CustomerID")
End Sub 

See also

Applies to