Shaarad Dalvi Shaarad Dalvi - 1 month ago 25
SQL Question

C# SqlDataReader interface with HasRows, Read() and NextResult()

I am trying to find an interface which is implemented by SqlDataReader and which exposes HasRows, Read() and NextResult(). I need these property and methods because I need to read multiple resultSets returned by stored procedures (as mentioned here). Currently I am using System.Data.IDataReader which exposes Read() and NextResult() but not HasRows property.

I need an interface so that the coupling will be lose and for the sake of code testability.

Any help on such an interface? Or I'll need to write an abstraction layer of interface from scratch?

usr usr
Answer

HasRows is not needed for anything (usually it's being used redundantly because people don't know any better). The standard pattern is:

while (reader.Read()) ...

So this obviates the need for the interface you are looking for.