大家好我怎样才能更简单地编写下面的代码? ...在一个查询中有两个sql(OleDb)命令。
con.open();
cmd.CommandText = "DELETE * FROM Customers WHERE ID_C = 1";
cmd.ExecuteNonQuery();
cmd.Clone();
cmd.CommandText = "DELETE * FROM Books WHERE ID_B = 1";
cmd.ExecuteNonQuery();
cmd.Clone();
con.close();
答案 0 :(得分:0)
如果您不需要受影响的行数(由ExecuteNonQuery
返回),您只需将两个命令放在以“;”分隔的同一SQL中
con.open();
cmd.CommandText = "DELETE * FROM Customers WHERE ID_C = 1; DELETE * FROM Books WHERE ID_B = 1";
cmd.ExecuteNonQuery();
con.close();