How to parameterize a date type in access to resolve the problem with the data type mismatch in criteria expression

Source: Internet
Author: User

A recent project to use Access, accustomed to SQL Server, a sudden return to access is a bit of a habit. When you use Access to insert date data, the general report data type mismatch in criteria expression error, although I used a parameterized way to pass the value, but the problem is not resolved.

After testing, the following two methods can solve this problem.

Method One:

If you use a parameterized method, you can use DateTime.Now.ToString () to convert the date type to a string type. It seems that access is still quite silly.

Method Two:

When you use the normal method of spelling SQL, replace it with #. Because Access treats # as a date identifier. For example

String sql = "INSERT into table ([TIME]) VALUES (#2009 -01-01#)".

Finally, if you have a keyword in the column in the INSERT statement, Access reports that the insert failed, and the best solution is to enclose the column name in [].

If you want to reprint, please specify this article original from csdn tjvictor column: Http://blog.csdn.net/tjvictor

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.