The Size property of the SqlParameter

Source: Internet
Author: User

If size is not explicitly set in the size parameter, the size is inferred from the value of the DbType parameter.

If you think the above inferred that the size is inferred from the SqlDbType type, then you are wrong, it is actually inferred from the value of the parameter that you passed, such as the value that is passing over is "Shengzhen", the size value is 9, "Shanghai", the size value is 8.

So what kind of results will the different size values cause? The value of size does not simultaneously cause the execution plan of the database to be reused, so that the new execution plan is regenerated every time the SQL is executed, and the database execution time is wasted.

When instantiating SqlParameter, be sure to specify the Size property if it is a character type

For example

New SqlParameter ("@address", SqlDbType.VarChar, 4000)

If you have parameters such as int, Float, bigint,datetime, you can not specify the Size property. However, if size specifies an error, an unpredictable error may occur.

Reference: SqlParameter's Size property

This article is from the "Learning also leisure" blog, please be sure to keep this source

The Size property of the SqlParameter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.