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
是数据库的字符串路径,我已将其删除以缩短帖子,但建立了与数据库的连接并且一切正常。
答案 0 :(得分:2)
Table Name和WHERE之间没有空格,请放置如下空格:
"DELETE FROM Questions" + " WHERE
///^^^
不确定为什么必须使用字符串连接。这一切都可以与单个字符串相提并论。像:
using (OleDbCommand cmd = new OleDbCommand("DELETE FROM Questions WHERE ID=@ID", conn))
答案 1 :(得分:2)
您缺少空格,请更改
"DELETE FROM Questions" + "WHERE ID=@ID"
到
"DELETE FROM Questions WHERE ID=@ID"