I am trying to allow a user to select a table a 2 columns from that table for use in a query.
They define the provider and the connection string to choose the database. This is done using the DBProviderFactory and the DBConnectionStringBuilder. The problem seems to be when using the ODBC provider, other providers (OLEDB, Sql) seem ok.
I query the schema to get the tables. The user then chooses a table. As I only want to the user to be able to choose one string column and one numeric column I am trying to restrict the columns displayed for the chosen table based on their defined type in the schema. to do this I query the DataTypes collection and use the ProviderDbType column (which contains a number) and the DataType column (which contains the .Net system type) to build a map of DbType to System types.
I then query the schema for the table the user has chosen and based on the DATA_TYPE column in the result, look up the system type, so now I can allow the user to choose 1 column which is a string and another that is numeric. My problem is that for most database types this works, but for nchar the ProviderDbType is listed as 11 (in the DataTypes schema query), but when I get the columns of the table the DATA_TYPE is -8 (which is not a number in the ProviderDbType column).
How can I determine the type of the column correctly? Or am I doing something wrong?