OleDbParameter.Size Property

Definition

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

public override int Size { get; set; }
[System.Data.DataSysDescription("DbDataParameter_Size")]
public int Size { get; set; }

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 an OleDbParameter and sets some of its properties.

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

Remarks

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 100 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, OleDbType, 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 OleDbParameter property settings. For example, if the size of the parameter has been inferred, Size does not contain the inferred value after statement execution.

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.

If the size of the value supplied for an OleDbParameter exceeds the specified Size, the Value of the OleDbParameter contains the specified value, truncated to the size of the OleDbParameter.

Applies to

מוצר גירסאות
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also