C # access Database Operation Problems

Source: Internet
Author: User
When executing the UPDATE and INSERT statements, you need to input parameters. For example, the dal layer operation: 1 publicstaticvoidModifyUserList (UserListuserList) 2 {3 stringOleDbUPDATE + UserList + SET + 4 [UserName] @ UserName, + 5 [Password] @ Password +

When executing the UPDATE and INSERT statements, you need to input parameters, such as the dal layer operation: 1 public static void ModifyUserList (UserList userList) 2 {3 string OleDb = "UPDATE" + "UserList" + "SET" + 4 "[UserName] = @ UserName," + 5 "[Password] = @ Password" +

When executing the UPDATE and INSERT statements, you need to input parameters, such asOperation:

 1 public static void ModifyUserList(UserList userList)
2 {
3 string OleDb ="UPDATE "+"UserList "+"SET "+
4 "[UserName]=@UserName, "+
5 "[Password]=@Password "+
6 " WHERE [ID]=@ID";
7 try
8 {
9 OleDbParameter[] para = new OleDbParameter[]
10 {
11
12 new OleDbParameter("@UserName",userList.UserName),
13 new OleDbParameter("@Password",userList.Password),
14 new OleDbParameter("@ID",userList.ID)
15
16 };
17 DBHelper.ExecuteCommand(OleDb, para);
18 }
19 catch (Exception e)
20 {
21 Console.WriteLine(e.Message);
22 throw e;
23 }
24 }

At first, the insert and update statements failed, and an exception was thrown to indicate a syntax error. Later, I read some questions and answers from some netizens on the Internet. These two errors exist in the program:

1. When the field name conflicts with the ACCESS keyword, you must add the square brackets "[]" before the field name (resulting in an exception thrown by the Program)

2. The Parameter order is incorrect. ACCESS requires that the order of parameters in the parameter group be the same as that in the SQL statement (the program runs normally, but the number of affected rows returned by the statement is always 0)

When I press 1 at first, the program will not throw an exception but after executionDatabaseNo changes, and then I adjusted the Parameter order by 2, and modified it smoothly.Database.

MyProblemYes:

1. The three names of my table fields are ID, Password, and UserName. I checked the reserved words of ACCESS. Why are these three names not keywords still throwing an exception?

2. ACCESS requires that the order of parameters in the parameter group be the same as that in the SQL statement.ProblemIs ACCESSDatabaseOr is Microsoft's. NET class library not well configured for ACCESS ??

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.