[dba-VB] C# - Records Affected

jwcolby jwcolby at colbyconsulting.com
Tue Dec 1 10:50:57 CST 2009


Sorry for the ring, I found the problem.

The SP that I took this code from actually worked but the code I was testing did not and came before 
this code.  The problem was simply that in the SP I did not place the line that captured @@RowCount 
immediately after the EXEC (@SQL) statement.

All of the examples clearly warned me that this was a requirement but you understand "senior moments".

Anyway, this is now working.

Piece by piece this thing is coming together.

John W. Colby
www.ColbyConsulting.com


jwcolby wrote:
> I am trying to get a count of records appended, updated etc in my SPs and returning that to my C# 
> supervisor.  I am finding references to @@Rowcount however this is returning 1 instead of the actual 
> number.
> 
> Is this @@RowCount the real deal?
> 
> The SP definition:
> 
> ALTER PROCEDURE [dbo].[sp_AZOut_AZExportToOrderedChunk]
> 	-- Add the parameters for the stored procedure here
> 	@DBName varchar(50),
> 	@ErrorDesc varchar(4000) output,
> 	@ErrorNo int output,
> 	@RecsAffected int output
> 
> AS
> BEGIN
> 
> 
> Setting the returned value
> 
> 	EXEC (@SQL)
> 	select @RecsAffected = @@RowCount
> 
> My c# code:
> 
> intRecsAffected = sCmd.Parameters["@RecsAffected"].Value
> 
> The code triggers the try block if there is no such parameter (I just ignore it) or returns 1 if the 
> parameter exists.
> 
> This is a functioning tested SP which typically appends millions of records, though the exact number 
> depends on the database.
> 
> Is there something I need to know here?



More information about the dba-VB mailing list