
Determine Column Data Type at run time
LT,
I know you are looking for ODBC sample code, but if you decide to go with
ADO/ADOX, this may be of some help:
regards
Roy Fine
(ps - please excuse absence of error handling / catch blocks / comments /
etc -- )
(ps - although the below does seem to work, MSDN is always the definitive
source)
rlf
/* */
/* *********************************** */
#include "stdafx.h"
#import "c:\Program Files\Common Files\system\ado\msadox.dll"
#import "C:\Program Files\Common Files\System\ado\msado25.tlb" \
rename("EOF", "EndOfFile") no_namespace
_ConnectionPtr pCS;
/* */
/* *********************************** */
void doADOX(){
ADOX::_CatalogPtr m_pCatActDB = NULL;
ADOX::_ColumnPtr m_pColFirstName = NULL;
m_pCatActDB.CreateInstance(__uuidof (ADOX::Catalog));
m_pColFirstName.CreateInstance(__uuidof(ADOX::Column));
m_pCatActDB->PutActiveConnection(_variant_t((IDispatch *)pCS,true));
m_pColFirstName =
m_pCatActDB->Tables->GetItem("AccountMaster")->Columns->GetItem("FName");
_bstr_t colName = m_pColFirstName->Name;
int colType = m_pColFirstName->Type;
int colAttrib = m_pColFirstName->Attributes;
int colDefSize = m_pColFirstName->DefinedSize;
int colNumScale = m_pColFirstName->NumericScale;
int colPrecise = m_pColFirstName->Precision;
Quote:
}
/* */
/* *********************************** */
int main(int argc, char* argv[]){
::CoInitialize(NULL);
pCS.CreateInstance(__uuidof(Connection));
pCS->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\DevPrograms\\groups.mdb;","","",adConnectUnspecified);
doADOX();
pCS->Close();
pCS = NULL;
::CoUninitialize();
return 0;
Quote:
}
Quote:
> LT,
> If you are using ADO, then have a look at ADOX -- the
> Catalob->Table->Columns->Column. Check the type property when you have a
> pointer to the property. It is of DataTypeEnum (i.e. adBSTR, adDate,
> adInteger, adDouble, adWChar, etc...).
> Have a look at the following link:
> http://msdn.microsoft.com/library/en-us/ado270/htm/adobjcolumn.asp
> best regards
> Roy Fine
> > Does any one know a fast way to determine the data type for a column
> > at run time? Needs to use VC++ 6 and Access for the DB. Or maybe you
> > could suggest a better way of doing the following.
> > I need to create a SQL insert statement based on variable fields
> > and information. The fields can be numeric and/or char based. I need
> > to find the data type so that values can be properly wrapped in
> > quotes.
> > What would really be helpful is a coded example or two showing the
> > dynamic manipulation of an ODBC data source.
> > TIA