Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

OdbcParameter.Size Property

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

Namespace:  System.Data.Odbc
Assembly:  System.Data (in System.Data.dll)
public override int Size { get; set; }

Property Value

Type: System.Int32
The maximum size of the data within the column. The default value is inferred from the parameter value.

Implements

IDbDataParameter.Size
IDbDataParameter.Size

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.

NoteNote

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.

The following example creates an OdbcParameter and sets some of its properties.

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.