Re: Getting the data type of a column



Thank you Bob, it helped.

For anybody seraching for the same this is what I have done. I've given only
just main points of the code and no error checks are done in this code.

#import "C:\Program Files\Common Files\System\ado\msadox.dll"
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace
rename("EOF", "EndOfFile")

ADOX::_CatalogPtr catalog = NULL;
_ConnectionPtr conn = NULL;

catalog.CreateInstance(__uuidof (ADOX::Catalog))
conn.CreateInstance(__uuidof( Connection ));

_bstr_t strCnn("Provider='Microsoft.JET.OLEDB.4.0';data
source='c:\\test.mdb';");

conn->Open(strCnn, "", "", adConnectUnspecified);

catalog->PutActiveConnection( conn->ConnectionString );

printf("Data Type of column MYCOLUMN of table MYTABLE is: %d\n",
catalog->Tables->GetItem("MYTABLE")->GetColumns()->GetItem("MYCOLUMN")->Type);

-Kannan

"Bob Barrows [MVP]" wrote:

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: Determine actual size of binary column in result set
    ... you mean that you want to find out the amount of data inside a column. ... it seems that there is no good method with SQLBindCol. ... you may use the datatype "varbinary". ... character string or binary data type. ...
    (microsoft.public.data.odbc)
  • Re: Remote View Boolean Fields
    ... conversion required by DataType property for field is invalid" error. ... converted to a foxpro logical but for whatever reason it doesn't it I can't ... specify logical as a datatype for a boolean datatype in Postgresql. ... VFP's Logical data type is automatically converted to ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Want To Read Float In Record As Is
    ... Float an real are generally referred to as "approximate" datatype. ... But you probably want to look ad NUMERIC or DECIMAL (these are identical in SQL Server). ... What I mean is that no matter what data type I use in variables ...
    (microsoft.public.sqlserver.programming)
  • 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: Datatype conversions from SQL to Access
    ... way data type. ... Just uncheck Allow Nulls so it is 2 way. ... > a datatype in SQL that will convert to Yes/No in Access. ...
    (microsoft.public.access.externaldata)