reader.GetSchemaTable on Oracle database does not return a DataTypeName column

776 Views Asked by At

Doing a table = reader.GetSchemaTable(); on sql server 2005 returns me a column DataTypeName to find out the datatype of my select statement.

Doing the same code on a oracle server returns me NO DataTypeName column.

How do you then get the datatype name for a column1 field using a select column1 from tablename statement ?

2

There are 2 best solutions below

0
On

When using Oracle, DbDataReader.GetSchemaTable doesn't work.

You can use OracleDataReader.GetSchemaTable.

Another option would be to iterate thorugh DbDataReader fields, like this:

    public bool Test(DbDataReader _dr, string columnName)
    {
        for (int i = 0; i <= _dr.FieldCount - 1; i++)
        {
            if ((_dr.GetName(i).Equals(columnName, StringComparison.InvariantCultureIgnoreCase)))
            {
               //Change this to your needs
               _dr.GetDataTypeName(i);
               return true;
            }
        }
        return false;
    }
1
On

Well which reader are you using, there is OracleDataReader.GetSchemaTable Method which should give what you want