Link to home
Start Free TrialLog in
Avatar of gamesmeister
gamesmeisterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

OleDB Type Mappings in an OleDbDataAdapter

I'm using the FillSchema method of an OleDbDataAdapter to retrieve the schema of some tables in my DB2 database. Unfortunately, columns of type Date, Time, and Timestamp are all mapped to a System.DateTime type, which is too generic for my application - I need to display the actual type (i.e Date, Time or Timestamp).

Is it possible for me to intercept the OleDbType of the column before it's mapped? And even if I can do that, how could I then store the type correctly within a DataColumn?

Many thanks
Gerry
Avatar of KenLange
KenLange


Gerry,

The System.DateTime type can represent all of the possible values of a DB2 Date, Time, or Timestamp.  It should meet all of your needs.  i.e. if you only want to represent the Date, then ignore the Time part of the DateTime value.

Perhaps if you explained what you want to do with the value after you fill a DataSet using FillSchema someone would be able to point you in the right direction.


If you just want to display the value, there are many methods of DateTime that allow you to display just the Date, Just the Time or the Timestamp or whatever you want.

KL
Avatar of gamesmeister

ASKER

Thanks for the response

I want to display the schema of a DB2 database to my user i.e for a selected table, the user can see details of the columns in that table, including name, length and type. Therefore, if a column in the database is of the the type Time, I want to display that on a window. At the moment, FillSchema is just giving me a System.DateTime, and I've no idea whether that's a Date, a Time, or a Timestamp.

To make thngs slightly more difficult, it's possible that the tables will be empty, which means I can't extrapolate the type from data within the column.

Thanks
Gerry
ASKER CERTIFIED SOLUTION
Avatar of KenLange
KenLange

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome, thx KL.

I have used this before, to get a list of table names within the database, but information on its usage is pretty sparse. Thx for all the examples, they're a big help. If you have any links that might give me the various options available, that would be very helpful, but this will keep me definitely keep me going for now.

Thx again
Gerry
You're welcome.  

I don't have any links with more info.  But, once you understand how GetOleDbSchemaTable works
then it's just a matter of going through the .Net  help for the members of "OleDbSchemaGuid" and seeing what information you get with each one as well as what "Restrictions" are available.

Also, the fact that you can cast the  DATA_TYPE int32 values into an OleDbType enum is very useful.  I didn't find that written anywhere, it just seemed like a good idea so I tried it and sure enough they match. Somebody thinks like me! (God help us)

Good Luck.