Search code examples
c#.netidatareader

How to convert/cast SqlDataReader to IDatareader


What is the easiest way to cast a SqlDataReader to IDatareader.

Or is it easier / possible to convert a List<> object to a IDataReader


Solution

  • What is the easiest way to convert a SqlDataReader to IDatareader

    Since SqlDataReader implements IDataReader, this is just an implicit cast:

    SqlDataReader typedReader = ...
    IDataReader untypedReader = typedReader;