简体   繁体   English

SqlParameter 构造函数整数长度问题

[英]SqlParameter Constructor Integer length issue

I'm currently debugging an SQL query that deletes through C# an item in a SQL server table based on a number of parameters.我目前正在调试一个 SQL 查询,该查询根据多个参数通过 C# 删除 SQL 服务器表中的一个项目。 Currently this statement is failing.目前这个说法是失败的。

One of the parameters supplied is based on a version ID of the item.提供的参数之一基于项目的版本 ID。

The SQL parameter for this version ID is:此版本 ID 的 SQL 参数为:

new SqlParameter("@versionId", SqlDbType.Int, 4)

If, for example, the query was supplied with the version ID 51096, would it fail on this integer parameter with a set length of '4'?例如,如果查询提供的版本 ID 为 51096,它是否会在设置长度为“4”的整数参数上失败?

No it won't fail.不,它不会失败。 Even if you put 0 here, in size, it will work but if your db type is varchar or nvarchar then it will truncate your value to the supplied size, in this case 4.即使你把 0 放在这里,在大小上,它也会工作,但如果你的数据库类型是varcharnvarchar那么它会将你的值截断到提供的大小,在这种情况下是 4。

If your parameter value is more than what an int can hold ( 2,147,483,647 ) then it will throw an error at runtime.如果您的参数值大于 int 可以容纳的值( 2,147,483,647 ),那么它将在运行时抛出错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM