SqlCommand Parameters size confusion

荒凉一梦 提交于 2019-12-01 15:45:02

For the types with fixes size you should omit this argument, simply:

sqlcommand.Parameters.Add("@LinkID", SqlDbType.Int).Value = linkID;

The size argument is only relevant for parameters with a type that can have variable size like varchar, nvarchar etc.

The size is 4 bytes for an int.

See DbParameter class on msdn for more info. It is relevant because SqlCeParameter implements DbParameter

The following section is relevant:

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.

See this https://gist.github.com/1932766 for the implementation of the Size property.

It is 4 bytes, 32 bits. It is a 32 bit integer.

if you are going for int than i think therre is no matter what size of it.

so you code will be

sqlcommand.Parameters.Add("@LinkID", SqlDbType.Int).Value = linkID; 

on for varchar,navarchar where the size is maater you need to speicify size in you .net code i.e in parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!