SqlCommand参数大小混淆 [英] SqlCommand Parameters size confusion

查看:63
本文介绍了SqlCommand参数大小混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码行:

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

但是,对于size的使用,我有些困惑.这是说它的4字节大小吗?还是长度为4,所以1234是可以接受的,但12345太大了?

But, I'm slightly confused about the use of size. Is this saying that its 4 bytes in size? Or a length of 4 so 1234 is acceptable but 12345 is too big?

推荐答案

对于具有修正大小的类型,您应该忽略此参数,只需:

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

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

size参数仅与类型可以具有可变大小的参数有关,例如varcharnvarchar等.

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

这篇关于SqlCommand参数大小混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆