Using "rows affected" to manipulate code

  • Thread starter Thread starter Kiki
  • Start date Start date
K

Kiki

Hi,
just a small question. I've just looked at a friends code and he's done this:
int rowsAffected = sql.ExecuteNonQuery("stored_procedure", cmdParams);

if(rowsAffected < 1)
{
return false;
}
else
{.......
}

of course the code broke as soon as i put SET NOCOUNT ON in the sp..

is there a better way to check if any rows have been affected?

Thank you
Kiki
 
You need to get that info back one way or the other. If you just pull a
datatable/dataset back you can check the Rows.Count property of the given
table. But for updates, you need to either use what he did or specify an
output parameter or return value. Check out www.betav.com -> Articles->
MSDN - Retrieving the Gozoutas - Bill Vaughn has a great discussion of this.

HTH,

Bill
 
Back
Top