• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Getting ADO Column Type

I'm writing to an Access db using ado under VC6 and I need to update a field. I need to determine the field's variant type before setting the field (or else ADO will cause an exception). I'm guessing this information might come from the OpenSchema call in Recordset. This is where I'm getting the table and column names. If someone could give a quick example it would be helpful (It could even be from another language since the calls would be similar).
  • 2
1 Solution
You can open the table with a recordset, using the following syntax:

rs->Open ("Employees", CONNECTION_STRING, adOpenStatic, adLockReadOnly, -1)

Where "Employees" is the table name, then you can access the field type like so:


Use 1 or 0 or 2, whatever...  Then you need to map the Type which is a value from the DataTypeEnum to a VARTYPE.

If this is an operation you are going to do repeatedly it's best to do it during program initialization and keep the info cached.



Change this:
rs->Open ("Employees", CONNECTION_STRING, adOpenStatic, adLockReadOnly, -1)

To this:
rs->Open (_variant_t(L"Employees"), _variant_t(CONNECTION_STRING), adOpenStatic, adLockReadOnly, -1)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now