Редагувати

Поділитися через


SqlParameter.Size Property

Definition

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

public:
 virtual property int Size { int get(); void set(int value); };
public:
 property int Size { int get(); void set(int value); };
public override int Size { get; set; }
[System.Data.DataSysDescription("DbDataParameter_Size")]
public int Size { get; set; }
member this.Size : int with get, set
[<System.Data.DataSysDescription("DbDataParameter_Size")>]
member this.Size : int with get, set
Public Overrides Property Size As Integer
Public Property Size As Integer

Property Value

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

Implements

Attributes

Examples

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.InputOutput;
    parameter.Size = description.Length;
    parameter.Value = description;
}
Private Sub CreateSqlParameterSize()
    Dim description As String = "12 foot scarf - multiple colors, one previous owner"
    Dim parameter As New SqlParameter("Description", SqlDbType.VarChar)
    parameter.Direction = ParameterDirection.InputOutput
    parameter.Size = description.Length
    parameter.Value = description
End Sub

Remarks

Return values are not affected by this property; return parameters from stored procedures are always fixed-size integers.

For output parameters with a variable length type (nvarchar, for example), the size of the parameter defines the size of the buffer holding the output parameter. The output parameter can be truncated to a size specified with Size. For character types, the size specified with Size is in characters.

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.

For information about streaming, see SqlClient Streaming Support.

Applies to

See also