Failed to convert from string to datetime

Source: Internet
Author: User

When using LINQ today, because the time in the database is saved in the varchar () format, the query time needs to be compared, so we use:

 

 
From J in system. jhzdwhere J. dwbm. tostring (). trim () = branchcode. tostring (). trim () & convert. todatetime (J. yearmonth. tostring (). trim ()). compareto (convert. todatetime (timefrom)> = 0 & convert. todatetime (J. yearmonth. tostring (). trim ()). compareto (convert. todatetime (timeto) <= 0 join B in system. t_sys_branchon J. dwbm. tostring (). trim () equals B. branchcodejoin C in system. t_cwlbon J. xmlb. tostring (). trim () equals C. idselect new {branchname = B. branchname, Category = C. CWMC, money = J. je, comefrom = J. zjly, time = J. yearmonth, zhaiyao = J. zhaiyao ,}

However, database reports are discovered during use. "Failed to convert from string to datetime".

 

I tried a lot of methods and still didn't use them. I finally found that the string of the yearmonth field in the database is"January 04, 2013",

When you change it to "", the query is normal and valid.

 

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.