I want to check if my query in methode ExecuteNonQuery() is running.
here is my code in my WCF Service:
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;
}
ExecuteNonQuery()returns an integer which will be the sum of rows affected by your sql statement. i.e. if SSMS returned:ExecuteNonQuery()would return 737.So you could use something like this.
You should also consider a
usingblock for your SqlCommand as well as your SqlConnection.