I want SqlCommand to return nothing, just do

425 views Asked by At

I have a stored procedure that does a lot of stuff based on if the person's password fits the criteria. I don't need it to return anything. Just execute the procedure.

I was looking at THIS and it seems all of the Execute(blah) extensions return something. Is there an Execute(blah) for SqlCommand that just executes the procedure and doesn't return anything?

2

There are 2 answers

0
William Xifaras On BEST ANSWER

You can use ExecuteNonQuery. It will return the number of rows affected, just don't assign it.

        using (var conn = new SqlConnection("YOUR CONNECTION STRING"))
        {
            using (var command = new SqlCommand("YOUR PROCEDURE NAME", conn))
            {
                command.CommandType = CommandType.StoredProcedure;
                conn.Open();
                command.ExecuteNonQuery();
            }
        }
3
pacreely On

I think you might be looking for the "SET NOCOUNT" statement.

https://msdn.microsoft.com/en-us/library/ms189837.aspx

It prevents Transactions and Stored procedures from returning the extra messages about what it did.