【发布时间】:2015-10-20 09:13:41
【问题描述】:
像这样使用 Access 数据库:
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Request.PhysicalApplicationPath + "Resources/cars_db.accdb");
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO Users (Username, Password, Email, Address, Question, Answer) VALUES ('" + txtUsernameRP.Text + "','" + txtPasswordRP.Text + "','" + txtEmailRP.Text + "','" + txtAddressRP.Text + "','" + txtQuestionRP.Text + "','" + txtAnswerRP.Text + "')";
int i = cmd.ExecuteNonQuery(); -- **Breaks here and says syntax error**
我试过了:
- 取出 int i 位。
- 将@符号放在语句前面。
- 检查并确保我使用的是访问代码。
- 在创建之前尝试关闭连接,以防它在那里。
- 将数据替换为固定值,然后我在 Access 中的一个查询中运行该值。
- 将上面提到的访问查询放入代码块(cmd.CommandText = "INSERT INTO Users(Username, Password, Email, Address, Question, Answer) VALUES ('asdasd','Asd! 23asd','asdasd','asdasd','asdasd','asdasd')"; 并尝试运行它并再次出现相同的语法错误。
请有人帮助我...
【问题讨论】:
-
您是否有任何特定的语法错误(近线...)?还是只是一般的语法错误?
-
你在 nr 6 中错过了一次paranteces。我不知道这是否重要,但是......
-
根据您的查询生成的“(”在用户之后丢失。
-
那么,如果你使用Access,为什么要添加MySQL标签?
-
您是否在代码之外尝试过此请求?