Determine Column Data Type at run time 
Author Message
 Determine Column Data Type at run time

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



Sat, 04 Sep 2004 00:21:22 GMT  
 Determine Column Data Type at run time

Quote:

> 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

See the ODBC Catalog... functions and the MFC CATALOG sample
application.

--
Scott McPhillips [VC++ MVP]



Sat, 04 Sep 2004 07:24:59 GMT  
 Determine Column Data Type at run time
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


Quote:
> 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



Sat, 04 Sep 2004 08:00:26 GMT  
 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



Sat, 04 Sep 2004 11:04:37 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Determining type at run-time or compile-time

2. Determining variable type at run-time (followup q.)

3. Determining variable type at run-time

4. Data types at run time

5. determining the available storage on the stack at run time

6. Passing a pointer when data type is un-determined

7. Determining the data type of an variable

8. Determine Data type of Value in an Edit Box

9. data type of a column / buffer size of a field

10. Data Types for Image Column

11. run time type checking

12. Choose type of the object in run-time

 

 
Powered by phpBB® Forum Software