SqlParameter.Size 属性

定义

获取或设置列中数据的最大大小(字节)。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

属性值

Int32

列中数据的最大大小(字节)。The maximum size, in bytes, of the data within the column. 默认值将根据参数值进行推断。The default value is inferred from the parameter value.

实现

属性

示例

下面的示例创建 SqlParameter 并设置其一些属性。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

注解

返回值不受此属性影响;从存储过程返回参数总是固定大小的整数。Return values are not affected by this property; return parameters from stored procedures are always fixed-size integers.

对于长度为可变的输出参数 (nvarchar (如) ),参数的大小定义了包含 output 参数的缓冲区的大小。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. 可以将 output 参数截断为使用指定的大小 SizeThe output parameter can be truncated to a size specified with Size. 对于字符类型,用指定的大小 Size 为字符。For character types, the size specified with Size is in characters.

Size属性用于二进制和字符串类型。The Size property is used for binary and string types. 对于类型的参数 SqlType.StringSize 表示 Unicode 字符中的长度。For parameters of type SqlType.String, Size means length in Unicode characters. 对于类型为的参数 SqlType.XmlSize 将忽略。For parameters of type SqlType.Xml, Size is ignored.

对于非字符串数据类型和 ANSI 字符串数据, Size 属性是指字节数。For nonstring data types and ANSI string data, the Size property refers to the number of bytes. 对于 Unicode 字符串数据, Size 是指字符数。For Unicode string data, Size refers to the number of characters. 字符串的计数不包括终止字符。The count for strings does not include the terminating character.

对于可变长度数据类型, Size 描述要传输到服务器的最大数据量。For variable-length data types, Size describes the maximum amount of data to transmit to the server. 例如,对于 Unicode 字符串值,可 Size 用于将发送到服务器的数据量限制为前100个字符。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.

对于固定长度数据类型, 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.

有关流式处理的信息,请参阅 SqlClient 流支持For information about streaming, see SqlClient Streaming Support.

适用于