简体   繁体   中英

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. Currently this statement is failing.

One of the parameters supplied is based on a version ID of the item.

The SQL parameter for this version ID is:

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'?

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.

If your parameter value is more than what an int can hold ( 2,147,483,647 ) then it will throw an error at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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