我想检查我在方法 ExecuteNonQuery() 中的查询是否正在运行。这是我在 WCF 服务中的代码:
public string Execute(string query){
string connectionString = ConfigurationManager.ConnectionStrings["ConnWf"].ConnectionString;
string hasil = "ERROR";
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
string cmdStr = String.Format(query);
SqlCommand command = new SqlCommand(cmdStr, conn);
command.Connection.Open();
command.ExecuteNonQuery();
//I want to check here..
if (command.ExecuteNonQuery().HasRows) //it doesn't works :(
{
hasil = "SUCCESS \n Row Affected: " + rd.RecordsAffected;
}
else
{
hasil = "FAILED \n Row Affected: " + rd.RecordsAffected;
}
conn.Close();
}
return "Query: "+query+"\n Status: "+hasil;
}