Problems encountered when migrating the Dal layer from SQL Server to access

Source: Internet
Author: User

1) exception: ierrorinfo. getdescription failed because of e_fail (0x80004005.
The main cause of this problem is that the SQL statement executed on Access contains components not supported by access (such as functions in SQL Server ).

2) unable to update

After the table is migrated to access, it is found that the table cannot perform new operations, and no error is reported.

The main cause of this problem is that the SQL statements built in the Dal layer are inconsistent with the matching Parameter order. As follows:

Code
Oledbcommand comm = dalmailfactory. createoledbcommand ();
Comm. commandtext = "Update mailcontacts set name = @ name, email = @ email, description = @ description, username = @ username where id = @ ID ";

// Comm. Parameters. addwithvalue ("@ ID", Ent. ID); // #1
Comm. Parameters. addwithvalue ("@ name", Ent. Name );
Comm. Parameters. addwithvalue ("@ email", Ent. Email );
Comm. Parameters. addwithvalue ("@ description", Ent. Description );
Comm. Parameters. addwithvalue ("@ username", Ent. username );
Comm. Parameters. addwithvalue ("@ ID", Ent. ID); // #2

Return oledbhelper. executenonquery (Comm );
/**//*
* In commandtext, the order of parameters is @ name, @ email, @ desciption, @ username, @ ID)
*
* The following parameter values cannot be updated if @ ID is written to #1. The @ ID must be written to the position #2 in the same order as the parameters in commandtext to be updated successfully.
*/

 

3) syntax error of insert into statement

The main cause of this error is that the SQL statement is written in a lazy manner, and the field in the table is not added with []. As follows:

Code
Insert into userbaseinfo ([username], [Password], [name].
Values (@ username, @ password, @ name.

/*
This error may occur if [] is not added to username, password, and name.
This is not to say that these three words will cause this error. I still have many fields not written after the statement.
*/

 

 

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.