Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No. of affected rows using ExecuteNonQuery

Status
Not open for further replies.

Dhinga

Programmer
Jun 15, 2006
9
US
Hi,

I am executing a stored procedure using the ExecuteNonQuery method of the command object. I am trying to get the number of affected rows by the stored procedure. But I am always getting -1 as the rows affected although my stored procedure return 1 record. Any idea why this is happening. Thanks in advance for help.

Thanks
Hitesh Kapadia
 
It is a select query. I want to show the number of affected rows on my ASP.NET page.

Thanks
Hitesh Kapadia
 
From Visual Studio Help
You can use ExecuteNonQuery to perform catalog operations (for example, querying the structure of a database or creating database objects such as tables), or to change the data in a database by executing UPDATE, INSERT, or DELETE statements.

Although ExecuteNonQuery does not return any rows, any output parameters or return values mapped to parameters are populated with data.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.

If you want to display the number of rows selectd, then count the number of rows in your datasouce(ie dataset, datatable..etc)

Jim
 
Thanks. I did use count to get the total rows affected. Thanks anyway.

Hitesh Kapadia
 
one more thing that i noticed, ExecuteNonQuery doesnt seem to return the value at all! when you use a command object then it returns the value as the first output parameter!

any examples to the contrary???

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top