Re: Getting the data type of a column



Kannan wrote:
Hi,
I am writing a program in C++ to get data from an MS Access mdb file.
What I need is to get is the data type of a column, given the table
name and the column name. How will I do it C++? I think something
can be done by using

rec = conn->OpenSchema(adSchemaColumns, vtCriteria, vtMissing);
//where vtCriteria is {Empty, Empty, TableName, Empty}

but when I try to get the column data type as below, it fails at
GetItem() call fails.

DataTypeEnum dataType;
rec->Fields->GetItem("ColumnName")->get_Type( &dataType );

I know that from the result of a SQL select query I can call
"get_Type()" on the column field and get the data type. But what I
need to know how to get the properties (including the datatype) of a
column in a table.

I am coding in C++ not in VB or C#.


It appears you have failed to read the documentation, which can be found
here:
http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoapireference.asp

If you read the documentation for the SchemaEnum
(http://msdn.microsoft.com/library/en-us/ado/html/21c97651-297f-469f-b5b5-c48af72b62a8.asp?frame=true),
you would have seen that the recordset returned by adSchemaColumns does not
provide column datatype information.

In fact, OpenSchema seems to be useless for providing this type of
information. If you don't wish to query the field types of a recordset
opened on a table, your only recourse is to use ADOX.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


.



Relevant Pages

  • Re: Getting the data type of a column
    ... What I need is to get is the data type of a column, ... //where vtCriteria is {Empty, Empty, TableName, Empty} ... DataTypeEnum dataType; ... This email account is my spam trap so I ...
    (microsoft.public.data.ado)
  • Re: Nothing, Empty and Null
    ... that even in an error condition, an Integer (or any numeric data type) will ... I get the subtle Empty/Null distinction - Empty is ... 'Empty' applies only to Variant type variable. ... It is comparable to both 0 and vbNullString ...
    (microsoft.public.excel.programming)
  • Re: Nothing, Empty and Null
    ... had an "On Error Resume Next" statement, which causes VB/VBA to ignore the ... that even in an error condition, an Integer (or any numeric data type) will ... I get the subtle Empty/Null distinction - Empty is ... 'Empty' applies only to Variant type variable. ...
    (microsoft.public.excel.programming)
  • Re: Nothing, Empty and Null
    ... Many Many thanks Chip and sorry if this is a repeat post! ... I get the subtle Empty/Null distinction - Empty is ... default and can change data type - have to set to null and then can't set to ... 'Empty' applies only to Variant type variable. ...
    (microsoft.public.excel.programming)
  • Re: Nothing, Empty and Null
    ... 'Empty' applies only to Variant type variable. ... contains no valid data and is not any data type. ... It is comparable to both 0 and vbNullString ...
    (microsoft.public.excel.programming)