RecordsAffected Property (SqlShimDataReader)
Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
public override int RecordsAffected {get;}
'Declaration
Public Overrides ReadOnly Property RecordsAffected As Integer
Property Value
The number of rows changed, inserted, or deleted. -1 for SELECT statements; 0 if no rows were affected, or the statement failed.
This sample shows how to find out how many rows have been affected during last query. You can do it even if the
SqlShimDataReader has been closed.
public void ProcessReader (DynamicsDataReader dynamicsReader)
{
if (!dynamicsReader.IsClosed)
{
while (dynamicsReader.Read())
{
for (int i=0;i<dynamicsReader.FieldCount;i++)
{
Console.Write("\t"+dynamicsReader[i]);
}
Console.WriteLine();
}
}
else
{
Console.WriteLine("The DataReader is closed. Rows affected in last action: "+dynamicsReader.RecordsAffected);
}
}
Public Sub ProcessReader(ByVal dynamicsReader As DynamicsDataReader)
If Not dynamicsReader.IsClosed Then
Dim i As Integer
While dynamicsReader.Read()
For i = 0 To dynamicsReader.FieldCount - 1
Console.Write(" " & dynamicsReader(i))
Next i
Console.WriteLine()
End While
Else
Console.WriteLine("The DataReader is closed. Rows affected in last action: " & dynamicsReader.RecordsAffected)
End If
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2