Edit

Share via


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)
Obsolete.
Obsolete.

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)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

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
member 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

Applies to

Add(Object)

Source:
OleDbParameterCollectionHelper.cs
Source:
OleDbParameterCollectionHelper.cs
Source:
OleDbParameterCollectionHelper.cs

Adds the specified OleDbParameter object to the OleDbParameterCollection.

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

Parameters

value
Object

A Object.

Returns

The index of the new OleDbParameter object in the collection.

Implements

See also

Applies to

Add(String, OleDbType)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

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);
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
member this.Add : string * System.Data.OleDb.OleDbType -> System.Data.OleDb.OleDbParameter
Public Function Add (parameterName As String, oleDbType As OleDbType) As 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

Applies to

Add(String, Object)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

Caution

Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value) instead.

Caution

Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value). http://go.microsoft.com/fwlink/?linkid=14202

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) instead.")]
public System.Data.OleDb.OleDbParameter Add (string? parameterName, object? value);
public System.Data.OleDb.OleDbParameter Add (string parameterName, object value);
[System.Obsolete("Add(String parameterName, Object value) has been deprecated.  Use AddWithValue(String parameterName, Object value).  http://go.microsoft.com/fwlink/?linkid=14202", false)]
public System.Data.OleDb.OleDbParameter Add (string parameterName, object value);
[<System.Obsolete("Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value) instead.")>]
override this.Add : string * obj -> System.Data.OleDb.OleDbParameter
member this.Add : string * obj -> System.Data.OleDb.OleDbParameter
[<System.Obsolete("Add(String parameterName, Object value) has been deprecated.  Use AddWithValue(String parameterName, Object value).  http://go.microsoft.com/fwlink/?linkid=14202", false)>]
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

Applies to

Add(String, OleDbType, Int32)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

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);
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
member this.Add : string * System.Data.OleDb.OleDbType * int -> System.Data.OleDb.OleDbParameter
Public Function Add (parameterName As String, oleDbType As OleDbType, size As Integer) As 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

Applies to

Add(String, OleDbType, Int32, String)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

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);
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
member this.Add : string * System.Data.OleDb.OleDbType * int * string -> System.Data.OleDb.OleDbParameter
Public Function Add (parameterName As String, oleDbType As OleDbType, size As Integer, sourceColumn As String) As 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