FROM子句中的语法
本文关键字:语法 子句 FROM | 更新日期: 2023-09-27 17:50:20
private void DeleteQuestion_Click(object sender, EventArgs e)
{
try
{
using (OleDbConnection conn = new OleDbConnection(access7ConnectionString))
{
conn.Open();
using (OleDbCommand cmd = new OleDbCommand("DELETE FROM Questions" + "WHERE ID=@ID", conn))
{
cmd.Parameters.AddWithValue("@ID", currentRecord);
cmd.ExecuteNonQuery();
}
}
}
catch (OleDbException ex)
{
MessageBox.Show(ex.ToString());
}
}
我得到这个错误:
Syntax in FROM Clause
我哪里错了?还在学习c#
access7ConnectionString
是数据库的字符串路径,我已经把它剪掉以缩短帖子,但是与数据库的连接已经建立,并且一切都有效。
表名和WHERE之间不能有空格,必须有空格,如:
"DELETE FROM Questions" + " WHERE
///^^^
不太确定为什么必须使用字符串连接。所有这些都可以等同于一个字符串。如:
using (OleDbCommand cmd = new OleDbCommand("DELETE FROM Questions WHERE ID=@ID", conn))
您缺少一个空格,更改
"DELETE FROM Questions" + "WHERE ID=@ID"
"DELETE FROM Questions WHERE ID=@ID"