syntax error while inserting data into ms access table

前端 未结 3 760
孤街浪徒
孤街浪徒 2021-01-28 23:31

I have a following code:

OleDbConnection aConnection = new
                    OleDbConnection(\"Provider=Microsoft.ACE.OLEDB.12.0;
                                     


        
3条回答
  •  囚心锁ツ
    2021-01-29 00:09

    Password is a reserved word in Access so you need to wrap the password column in square brackets in your query. You also need to wrap the columns you're inserting data into in parentheses:

    INSERT INTO (Client cname,phone,[password]) VALUES(...
    

    As @HarveySpecter points out in the comments you should also use a parameterized query rather than concatenating user input otherwise you're opening yourself up to SQL injection attacks.

提交回复
热议问题