Considerations for operating ACCESS databases

Source: Internet
Author: User
The following problems are easy to ignore, but it is not easy to find out the problem, which makes me a lot of headaches, so here is a summary, also for others! 1. When you run an SQL command in the form of parameters, the parameter array must be exactly the same as the location and name of the parameter name in the SQL statement. Otherwise, the execution fails, but no error is reported. sqlinsertt

The following problems are easy to ignore, but it is not easy to find out the problem, which makes me a lot of headaches, so here is a summary, also for others! 1. when you run an SQL command in the form of parameters, the parameter array must be exactly the same as the location and name of the parameter name in the SQL statement. Otherwise, the execution fails, but no error is reported; SQL = "insert t

The following problems are easy to ignore, but it is not easy to find out the problem, which makes me a lot of headaches, so here is a summary, also for others!

1. When you run an SQL command in the form of parameters, the parameter array must be exactly the same as the location and name of the parameter name in the SQL statement. Otherwise, the execution fails, but no error is reported;

SQL = "insert table (a, B, c) values (@ a, @ B, @ c )"

Params = {@ a, @ c, @ B} ---> This is incorrect.

Params = {@ a, @ B, @ c} ---> This is correct.

2. When the SQL command is executed in the form of parameters, when the field type is time type, you need to explicitly declare the parameter type as Date, not in the form of parameter name + Value

SQL = "update table set editdate = @ dt"

Param = new oledbparameter ("@ dt", DateTime. Now) --> This is an error. An error is reported during execution: the data type in the standard expression does not match

Param = new oledbparameter ("@ dt", OleDbType. Date) {Value = DateTime. Now} --> This is correct

3. Pay attention to the reserved words in the ACCESS database. Do not use these words as field names. If you do need them, add square brackets to show instructions.

SQL = "update user set name = 'xxx'" --> This is incorrect.

SQL = "update [user] set [name] = 'xxx'" --> This is correct and displays non-system reserved words.

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.