ColumnExists

        /// <summary>
        /// Checks if a column exists in the DataReader
        /// </summary>
        /// <param name="dr">DataReader</param>
        /// <param name="ColumnName">Name of the column to find</param>
        /// <returns>Returns true if the column exists in the DataReader, else returns false</returns>
        public static Boolean ColumnExists(this IDataReader dr, String ColumnName)
        {
            for (Int32 i = 0; i < dr.FieldCount; i++)
                if (dr.GetName(i).Equals(ColumnName, StringComparison.OrdinalIgnoreCase))
                    return true;

            return false;
        }
Example:
Boolean b = datareader.ColumnExists("ColumnNameToCheck");

Description

Returns true if the column exists in the DataReader, else returns false

Details

Double click on the code to select all.

 

;