tags:

views:

18

answers:

2

I am using Pervasive and I would like to know what kind of data a column contains. However, the only overload of PsqlDataReader.GetFieldType accepts an int index. But I want to know using the column name. I guess I could just loop through all the columns and find the one with the specified name, but I do not want to do that.

Is there any way to find the data type of a column by a given column name?

A: 

I am not sure, but try use it like this

 SqlDataReader.GetFieldType["ColumnName"];
netmajor
Sorry, does not work. Please note that it is pervasive sql data reader
Oskar Kjellin
@Oskar - This wouldn't work with any SqlDataReader. GetFieldType is a method, not an indexed collection. There is also no overload that takes a string.
Justin Niessner
@Justin, I know. I just reacted on the fact that he removed the "P"
Oskar Kjellin
+1  A: 

You have to pair the use of GetFieldType with GetOrdinal (which returns the int index of the column):

PsqlDataReader.GetFieldType(PsqlDataReader.GetOrdinal("ColumnName"));
Justin Niessner
Thanks! :D Worked like a charm
Oskar Kjellin