dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlDataReader Class / RecordsAffected Property
Example

RecordsAffected Property (PgSqlDataReader)
Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
Syntax
'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.
Remarks
The value of this property is not cumulative. For example, if two records are inserted in the first statement in batch mode, and the second statement affected 3 records, the value of RecordsAffected will be 3.

System.Data.Common.DbDataReader.IsClosed and RecordsAffected are the only properties that you can call after the PgSqlDataReader is closed.

Example
This sample shows how to find out how many rows have been affected during last query. You can do it even if the PgSqlDataReader has been closed.
public void ProcessReader (PgSqlDataReader pgReader)
{
  if (!pgReader.IsClosed)
  {
    while (pgReader.Read())
    {
      for (int i=0;i<pgReader.FieldCount;i++)
      {
        Console.Write("\t"+pgReader[i]);
      }
      Console.WriteLine();
    }
  }
  else
  {
    Console.WriteLine("The DataReader is closed. Rows affected in last action: "+pgReader.RecordsAffected);
  }
}
Public Sub ProcessReader(ByVal pgReader As PgSqlDataReader)
  If Not pgReader.IsClosed Then
    Dim i As Integer
    While pgReader.Read()
      For i = 0 To pgReader.FieldCount - 1
        Console.Write(" " & pgReader(i))
      Next i
      Console.WriteLine()
    End While
  Else
    Console.WriteLine("The DataReader is closed. Rows affected in last action: " & pgReader.RecordsAffected)
  End If
End Sub
Requirements

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

See Also