I have a sample code
aCommand.CommandType = CommandType.StoredProcedure;
aCommand.Parameters.AddWithValue("@book_id", bookID);
aCommand.Parameters.AddWithValue("@user_id", userID);
and after that I want to execute a simple query using CommandText:
aCommand.CommandText = "SELECT * FROM aTABLE";
aCommand.ExecuteNonQuery();
but the error occurs:
Exception: Could not find stored procedure 'SELECT * FROM aTABLE'
In this case, I have to create a new instance of SqlCommand object ?
It is a way to use same SqlCommand object to avoid create one ?
SqlCommandis not so expensive that you need to reuse it. Actually the constructor does not more than setting the properties.aCommand.Parameters.Clear();