OdbcParameterCollection.Add OdbcParameterCollection.Add OdbcParameterCollection.Add OdbcParameterCollection.Add Method

Definition

Overloads

Add(OdbcParameter) Add(OdbcParameter) Add(OdbcParameter) Add(OdbcParameter)

Adds the specified OdbcParameter to the OdbcParameterCollection.

Add(Object) Add(Object) Add(Object) Add(Object)

Adds the specified OdbcParameter object to the OdbcParameterCollection.

Add(String, OdbcType) Add(String, OdbcType) Add(String, OdbcType)

Adds an OdbcParameter to the OdbcParameterCollection, given the parameter name and data type.

Add(String, Object) Add(String, Object) Add(String, Object) Add(String, Object)

Adds an OdbcParameter to the OdbcParameterCollection given the parameter name and value.

Add(String, OdbcType, Int32) Add(String, OdbcType, Int32) Add(String, OdbcType, Int32)

Adds an OdbcParameter to the OdbcParameterCollection, given the parameter name, data type, and column length.

Add(String, OdbcType, Int32, String) Add(String, OdbcType, Int32, String) Add(String, OdbcType, Int32, String)

Adds an OdbcParameter to the OdbcParameterCollection given the parameter name, data type, column length, and source column name.

Add(OdbcParameter) Add(OdbcParameter) Add(OdbcParameter) Add(OdbcParameter)

Adds the specified OdbcParameter to the OdbcParameterCollection.

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

Parameters

Returns

Exceptions

The OdbcParameter specified in the value parameter is already added to this or another OdbcParameterCollection.

See also

Add(Object) Add(Object) Add(Object) Add(Object)

Adds the specified OdbcParameter object to the OdbcParameterCollection.

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

Parameters

Returns

The index of the new OdbcParameter object in the collection.

See also

Add(String, OdbcType) Add(String, OdbcType) Add(String, OdbcType)

Adds an OdbcParameter to the OdbcParameterCollection, given the parameter name and data type.

public:
 System::Data::Odbc::OdbcParameter ^ Add(System::String ^ parameterName, System::Data::Odbc::OdbcType odbcType);
public System.Data.Odbc.OdbcParameter Add (string parameterName, System.Data.Odbc.OdbcType odbcType);
override this.Add : string * System.Data.Odbc.OdbcType -> System.Data.Odbc.OdbcParameter

Parameters

parameterName
String String String String

The name of the parameter.

odbcType
OdbcType OdbcType OdbcType OdbcType

One of the OdbcType values.

Returns

Examples

The following example adds an OdbcParameter to the Parameters collection.

public void CreateParamCollection() 
{
    OdbcCommand command = new OdbcCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OdbcParameterCollection paramCollection = command.Parameters;
    object paramObject = new OdbcParameter(
        "CustomerID", OdbcType.VarChar);
    int paramIndex = paramCollection.Add(paramObject);
}
Public Sub CreateParamCollection(connection As OdbcConnection)
  Dim command As OdbcCommand = New OdbcCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OdbcParameterCollection = command.Parameters
  Dim paramObject As Object = New OdbcParameter( _
    "CustomerID", OdbcType.VarChar)
  Dim paramIndex As Integer = paramCollection.Add(paramObject)
End Sub 
See also

Add(String, Object) Add(String, Object) Add(String, Object) Add(String, Object)

Warning

This API is now obsolete.

Adds an OdbcParameter to the OdbcParameterCollection given the parameter name and value.

public:
 System::Data::Odbc::OdbcParameter ^ Add(System::String ^ parameterName, System::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)]
[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.Odbc.OdbcParameter Add (string parameterName, object value);
override this.Add : string * obj -> System.Data.Odbc.OdbcParameter
Public Function Add (parameterName As String, value As Object) As OdbcParameter

Parameters

parameterName
String String String String

The name of the parameter.

value
Object Object Object Object

The Value of the OdbcParameter to add to the collection.

Returns

Exceptions

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 integer 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 OdbcParameterCollection.Add overload.

See also

Add(String, OdbcType, Int32) Add(String, OdbcType, Int32) Add(String, OdbcType, Int32)

Adds an OdbcParameter to the OdbcParameterCollection, given the parameter name, data type, and column length.

public:
 System::Data::Odbc::OdbcParameter ^ Add(System::String ^ parameterName, System::Data::Odbc::OdbcType odbcType, int size);
public System.Data.Odbc.OdbcParameter Add (string parameterName, System.Data.Odbc.OdbcType odbcType, int size);
override this.Add : string * System.Data.Odbc.OdbcType * int -> System.Data.Odbc.OdbcParameter

Parameters

parameterName
String String String String

The name of the parameter.

odbcType
OdbcType OdbcType OdbcType OdbcType

One of the OdbcType values.

size
Int32 Int32 Int32 Int32

The length of the column.

Returns

Examples

The following example adds an OdbcParameter to the OdbcCommand.Parameters collection.

public void CreateOdbcParamColl(OdbcConnection connection) 
{
    OdbcCommand command = new OdbcCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OdbcParameterCollection paramCollection = command.Parameters;
    OdbcParameter parameter = paramCollection.Add(
        "CustomerID", OdbcType.VarChar, 5);
}
Public Sub CreateOdbcParamColl(connection As OdbcConnection)
  Dim command As OdbcCommand = New OdbcCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OdbcParameterCollection = _
    command.Parameters
  Dim parameter As OdbcParameter = _
    paramCollection.Add("CustomerID", OdbcType.VarChar, 5)
End Sub 'CreateOdbcParamColl
See also

Add(String, OdbcType, Int32, String) Add(String, OdbcType, Int32, String) Add(String, OdbcType, Int32, String)

Adds an OdbcParameter to the OdbcParameterCollection given the parameter name, data type, column length, and source column name.

public:
 System::Data::Odbc::OdbcParameter ^ Add(System::String ^ parameterName, System::Data::Odbc::OdbcType odbcType, int size, System::String ^ sourceColumn);
public System.Data.Odbc.OdbcParameter Add (string parameterName, System.Data.Odbc.OdbcType odbcType, int size, string sourceColumn);
override this.Add : string * System.Data.Odbc.OdbcType * int * string -> System.Data.Odbc.OdbcParameter

Parameters

parameterName
String String String String

The name of the parameter.

odbcType
OdbcType OdbcType OdbcType OdbcType

One of the OdbcType values.

size
Int32 Int32 Int32 Int32

The length of the column.

sourceColumn
String String String String

The name of the source column.

Returns

Examples

The following example adds an OdbcParameter to the Parameters collection.

public void CreateParameterCollection(OdbcConnection connection) 
{
    OdbcCommand command = new OdbcCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OdbcParameterCollection paramCollection = command.Parameters;
    OdbcParameter parameter = paramCollection.Add(
        "CustomerID", OdbcType.VarChar, 5, "CustomerID");
}
Public Sub CreateParameterCollection(connection As OdbcConnection)
  Dim command As OdbcCommand = New OdbcCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OdbcParameterCollection = command.Parameters
  Dim parameter As OdbcParameter = paramCollection.Add( _
    "CustomerID", OdbcType.VarChar, 5, "CustomerID")
End Sub
See also

Applies to