Occasionally when working with recordsets returned by a stored procedure in an IDataReader, it can be helpful to print information about the columns returned. I like to do this when making a DTO class that mirrors a recordset to ensure that my class’s properties are typed consistently with the recordset. Printing the column details can be accomplished easily with the following code:
IDataReader reader = GetDataReader(); for (int i = 0; i < reader.FieldCount; i++) { Console.WriteLine("Name:{0}, Type:{1}", reader.GetName(i), reader.GetDataTypeName(i)); }