This documentation is archived and is not being maintained.

OdbcParameter.Size Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Gets or sets the maximum size of the data within the column.

[Visual Basic]
Public Overridable Property Size As Integer  Implements _
public virtual int Size {get; set;}
public: __property virtual int get_Size();
public: __property virtual void set_Size(int);
public function get Size() : int;
public function set Size(int);

Property Value

The maximum size of the data within the column. The default value is inferred from the parameter value.




The Size property is used for binary and string types.

For nonstring data types and ANSI string data, the Size property refers to the number of bytes. For Unicode string data, Size refers to the number of characters. The count for strings does not include the terminating character.

For variable-length data types, Size describes the maximum amount of data to transmit to the server. For example, for a Unicode string value, Size could be used to limit the amount of data sent to the server to the first one hundred characters.

For bidirectional and output parameters, and return values, you must set the value of Size. This is not required for input parameters, and if not explicitly set, the value of is inferred from the actual size of the specified parameter when a parameterized statement is executed.

The DbType, OdbcType, and Size properties of a parameter can be inferred by setting Value. Therefore, you are not required to specify them. However, they are not exposed in OdbcParameter property settings. For example, if the size of the parameter has been inferred, Size does not contain inferred value after statement execution.

Note   For an OdbcParameter with a Direction of ParameterDirection.Output, ParameterDirection.InputOutput, or ParameterDirection.ReturnValue, an exception is thrown when the command is executed if the size of the value returned by the data source exceeds the specified Size of the OdbcParameter.

For fixed-length data types, the value of Size is ignored. It can be retrieved for informational purposes, and returns the maximum amount of bytes the provider uses when transmitting the value of the parameter to the server.


[Visual Basic, C#, C++] The following example creates an OdbcParameter and sets some of its properties.

[Visual Basic] 
Public Sub CreateOdbcParameter()
    Dim myValue As String = "12 foot scarf - multiple colors, one previous owner"
    Dim myParameter As New OdbcParameter("Description", OdbcType.VarChar)
    myParameter.Direction = ParameterDirection.Output
    myParameter.Size = myValue.Length
    myParameter.Value = myValue
End Sub 'CreateAdoParameter

public void CreateOdbcParameter() 
    string myValue = "12 foot scarf - multiple colors, one previous owner";
    OdbcParameter myParameter = new OdbcParameter("Description", OdbcType.VarChar);
    myParameter.Direction = ParameterDirection.Output;
    myParameter.Size = myValue.Length;
    myParameter.Value = myValue;

    void CreateOdbcParameter()
        String* myValue = S"12 foot scarf - multiple colors, one previous owner";
        OdbcParameter* myParameter = new OdbcParameter(S"Description", OdbcType::VarChar);
        myParameter->Direction = ParameterDirection::Output;
        myParameter->Size = myValue->Length;
        myParameter->Value = myValue;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OdbcParameter Class | OdbcParameter Members | System.Data.Odbc Namespace