我有一张带有“SEMESTER、SUBJECT、OFFER、RESULT”的表格,其中“SEMESTER”和“SUBJECT”是主键。当我使用查询时
"DELETE FROM Course_Information WHERE Semester = 1 AND Subject = 'CSE-414' ;
它在访问数据库中完美运行,但是当我尝试在我的 C# 代码中使用它时,我总是遇到异常。
此外,如果我使用“DELETE FROM Course_Information WHERE Semester = 1 ;
我想在 WHERE 条件下同时使用“SUBJECT”和“SEMESTER”(因为同一学期可能有不同的主题)
看我的代码,
connection_string = aConnection.return_connectionString(connection_string);
string sql_query = "DELETE FROM Course_Information WHERE Semester = " + this.textBox1.Text + " AND Subject = " + this.textBox2.Text + " ;";
OleDbConnection connect = new OleDbConnection(connection_string);
OleDbCommand command = new OleDbCommand(sql_query, connect);
try
{
connect.Open();
OleDbDataReader reader = command.ExecuteReader();
MessageBox.Show("Delete Successful!");
connect.Close();
UpdateDatabase();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}