0

Hi, I am using a C# application that interacts with a TSQL stored procedure.

The problem is that my SqlDataReader property .RecordsAffected always returns -1 regardless of whatever kind of select, update, or delete query I run.

Here is my relevant code:

SqlDataReader myReader = null;

 SqlCommand command = new SqlCommand("CSP_CT_233", myConnection);
myReader = command.ExecuteReader();

while (myReader.Read())
        {

           blah blah blah //this stuff works fine
        }

myReader.Close();
Console.Writeline([B]myReader.RecordsAffected.ToString()[/B]);
2
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by LizR
0

Ok it works now ok, but when there is only 1 row affected, it will return 2, otherwise it works fine

0

The problem seems to be when my my update where field differs from my set field

(this is updating one record)

update table set field1=1 where field1=0 //returns 1
update table set field1=1 where field2=0 //returns 2

anyone seen this before?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.