Search code examples
c#npgsql

How to get number of rows from NpgsqlDataReader


I am trying to get the number of rows from the NpgsqlDataReader after using a select statement. The reason I am trying to check is to see if it has any data, a single row, or if it has multiple rows before working with the data. Any help will be greatly appreciated.

This is being done in C# .NET 4


Solution

  • From a bit of googling the NpgsqlDataReader would seem to be very similar to the sqldatareader. The sqldatareader does not have a built in way to get the row count. It would appear you would have to loop through and perform your own count if you wanted to get the rowcount.