This documentation is archived and is not being maintained.

SqlParameter.Size Property

Gets or sets the maximum size, in bytes, of the data within the column.

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public override int Size { get; set; }

Property Value

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

Implements

IDbDataParameter.Size
IDbDataParameter.Size

Setting Size affects only the input value of a parameter. Return values and output parameters are not affected by this property.

The Size property is used for binary and string types. For parameters of type SqlType.String, Size means length in Unicode characters. For parameters of type SqlType.Xml, Size is ignored.

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.

If not explicitly set, the size is inferred from the actual size of the specified parameter value.

If the fractional part of the parameter value is greater than the size, then the value will be truncated to match the size.

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 a SqlParameter and sets some of its properties.

static void CreateSqlParameterSize()
{
    string description = "12 foot scarf - multiple colors, one previous owner";
    SqlParameter parameter = new SqlParameter("Description", SqlDbType.VarChar);
    parameter.Direction = ParameterDirection.Output;
    parameter.Size = description.Length;
    parameter.Value = description;
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

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

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Show: