我可以捕获“ExecuteNonQuery”事件吗?例如,在下面的代码中,我想捕获ExecuteNonQuery命令:
private void test()
{
myConnection.Open();
sql = "Create Database DatabaseName";
cmd = new SqlCommand(sql,myConnection);
try
{
cmd.ExecuteNonQuery(); //CAPTURE THIS, send sql variable
}
catch (Exception ex)
{
//Do Something here
}
}
private void capturedExecuteNonQuery(sql)
{
MessageBox.Show("You captured it!" + sql);
}
任何有关完成此任务的建议都表示赞赏!