Database data type float to C # type decimal, float data Type conversion Invalid _ Practical tips

Source: Internet
Author: User
There was a sudden error in running the system today, the data type conversion was invalid, the error was in the System.data.sqlclient.get_decimal () method, and the initial estimate was that the float type of the database was converted to the decimal type of C #. The entity class uses a decimal type, thinking that even if the value in the database is empty, there is no conversion error.

A variety of online search, many people encounter a similar situation, most of the direct go to float type when the error, such as (float) dr[0], then see that there is said should be converted into a double, and then in the conversion to float on it



Try changing the decimal type of the entity class to double? type, OK.
Related Article

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.