我有一张桌子上有"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);
}
Run Code Online (Sandbox Code Playgroud)