About the "count type conflicts: nvarchar and image incompatible" issue

Source: Internet
Author: User

If the database is an image type, when the INSERT statement is executed, if the inserted value is Dbnull.value prompt: Operand type conflict: nvarchar is incompatible with image;

This problem occurs because there is no reason to specify DbType. In most cases, you do not need to specify the data type of the parameter (DbType or SqlDbType) when using SqlParameter, ADO. NET will automatically determine the type of data based on the type of value, even if it cannot be determined by ADO, SQL Server database servers can do most of the judgment (of course, some loss of performance).
But for the image type in this program is not so fortunate, if you do not specify DBTYPE, and the exact data is null/dbnull, the data type identified as nvarchar, the above error occurred. So just specify DbType or SqlDbType.

New SqlParameter ("@Photo", Sqlhelp.todbnull (employee. Photo)

New SqlParameter ("@Photo", Sqldbtype.image) {value=sqlhelp.todbnull (employee. Photo)}

So when using the above SqlParameter , will definitely error, with the following SqlParameter, because we specify the SqlDbType type is image, this error will not appear.

This article refers to the URL: http://bbs.itcast.cn/thread-11263-1-1.html

About the "count type conflicts: nvarchar and image incompatible" issue

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: info-contact@alibabacloud.com 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.