SQL插入语句不工作c#
本文关键字:工作 语句 插入 SQL | 更新日期: 2023-09-27 18:18:32
使用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**
I have try:
- 取出int i位
- 在语句前面加@符号
- 检查并确保我正在使用访问代码。
- 尝试在创建之前关闭连接,以防它在那里。
- 将数据替换为固定值,然后在Access中运行查询。
- 将上面提到的访问查询放入代码块(cmd)。CommandText = "INSERT INTO Users (Username, Password, Email, Address, Question, Answer) VALUES ('asdasd','Asd!23asd','asdasd','asdasd','asdasd','asdasd','asdasd','asdasd','asdasd')";并尝试运行它,再次出现相同的语法错误。
密码为保留关键字
cmd.CommandText = "INSERT INTO Users (Username, Password, Email, Address...
试试这个
cmd.CommandText = "INSERT INTO Users (Username, [Password], Email, Address...
你能试试吗?
"INSERT INTO Users (Username, Password, Email, Address, Question, Answer)
VALUES(
'" + txtUsernameRP.Text + "',
'" + txtPasswordRP.Text + "',
'" + txtEmailRP.Text + "',
'" + txtAddressRP.Text + "',
'" + txtQuestionRP.Text + "',
'" + txtAnswerRP.Text + "');";
我猜你的问题是在int i
上,试着删除它