Re: Getting the data type of a column
- From: Kannan <Kannan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 17 Apr 2007 11:46:04 -0700
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"
- References:
- Re: Getting the data type of a column
- From: Bob Barrows [MVP]
- Re: Getting the data type of a column
- Prev by Date: Re: Getting the data type of a column
- Next by Date: Gnome XSLT Processor
- Previous by thread: Re: Getting the data type of a column
- Next by thread: Gnome XSLT Processor
- Index(es):
Relevant Pages
|
|