Ole Db Consumer
-
**I am trying to create an Ole DB Consumer in order to access data from a table for a conduit application. The problem is that whenever I use the wizard to generate the code it does not generate the data members needed to correspond to the columns of the table I wish to work with. Do yo have any idea why this would happen? I can show you an example I saw on another website. Using the wizard with a table called Authors generates the code: // code generated on Wednesday, April 17, 2002, 10:25 AM
class CAuthorsAccessor
{
public:
** LONG m_Au_ID;
TCHAR m_Author[51];
SHORT m_YearBorn;**// The following wizard-generated data members contain status // values for the corresponding fields in the column map. You // can use these values to hold NULL values that the database // returns or to hold error information when the compiler returns // errors. See Field Status Data Members in Wizard-Generated // Accessors in the Visual C++ documentation for more information // on using these fields. // NOTE: You must initialize these fields // before setting/inserting data!
** DBSTATUS m_dwAu_IDStatus;
DBSTATUS m_dwAuthorStatus;
DBSTATUS m_dwYearBornStatus;**// The following wizard-generated data members contain length // values for the corresponding fields in the column map. // NOTE: For variable-length columns, you must initialize these // fields before setting/inserting data! DBLENGTH m\_dwAu\_IDLength; DBLENGTH m\_dwAuthorLength; DBLENGTH m\_dwYearBornLength; void GetRowsetProperties(CDBPropSet\* pPropSet) { pPropSet->AddProperty(DBPROP\_CANFETCHBACKWARDS, true, DBPROPOPTIONS\_OPTIONAL); pPropSet->AddProperty(DBPROP\_CANSCROLLBACKWARDS, true, DBPROPOPTIONS\_OPTIONAL); pPropSet->AddProperty(DBPROP\_IRowsetChange, true, DBPROPOPTIONS\_OPTIONAL); pPropSet->AddProperty(DBPROP\_UPDATABILITY, DBPROPVAL\_UP\_CHANGE | DBPROPVAL\_UP\_INSERT | DBPROPVAL\_UP\_DELETE); } HRESULT OpenDataSource() { CDataSource \_db; HRESULT hr; // Here goes the \_db.OpenFromInitializationString if (FAILED(hr)) {
#ifdef _DEBUG
AtlTraceErrorRecords(hr);
#endif
return hr;
}
return m_session.Open(_db);
}void CloseDataSource() { m\_session.Close(); }**
-
**I am trying to create an Ole DB Consumer in order to access data from a table for a conduit application. The problem is that whenever I use the wizard to generate the code it does not generate the data members needed to correspond to the columns of the table I wish to work with. Do yo have any idea why this would happen? I can show you an example I saw on another website. Using the wizard with a table called Authors generates the code: // code generated on Wednesday, April 17, 2002, 10:25 AM
class CAuthorsAccessor
{
public:
** LONG m_Au_ID;
TCHAR m_Author[51];
SHORT m_YearBorn;**// The following wizard-generated data members contain status // values for the corresponding fields in the column map. You // can use these values to hold NULL values that the database // returns or to hold error information when the compiler returns // errors. See Field Status Data Members in Wizard-Generated // Accessors in the Visual C++ documentation for more information // on using these fields. // NOTE: You must initialize these fields // before setting/inserting data!
** DBSTATUS m_dwAu_IDStatus;
DBSTATUS m_dwAuthorStatus;
DBSTATUS m_dwYearBornStatus;**// The following wizard-generated data members contain length // values for the corresponding fields in the column map. // NOTE: For variable-length columns, you must initialize these // fields before setting/inserting data! DBLENGTH m\_dwAu\_IDLength; DBLENGTH m\_dwAuthorLength; DBLENGTH m\_dwYearBornLength; void GetRowsetProperties(CDBPropSet\* pPropSet) { pPropSet->AddProperty(DBPROP\_CANFETCHBACKWARDS, true, DBPROPOPTIONS\_OPTIONAL); pPropSet->AddProperty(DBPROP\_CANSCROLLBACKWARDS, true, DBPROPOPTIONS\_OPTIONAL); pPropSet->AddProperty(DBPROP\_IRowsetChange, true, DBPROPOPTIONS\_OPTIONAL); pPropSet->AddProperty(DBPROP\_UPDATABILITY, DBPROPVAL\_UP\_CHANGE | DBPROPVAL\_UP\_INSERT | DBPROPVAL\_UP\_DELETE); } HRESULT OpenDataSource() { CDataSource \_db; HRESULT hr; // Here goes the \_db.OpenFromInitializationString if (FAILED(hr)) {
#ifdef _DEBUG
AtlTraceErrorRecords(hr);
#endif
return hr;
}
return m_session.Open(_db);
}void CloseDataSource() { m\_session.Close(); }**
I had the same problem when trying to use Ole DB in a ATL application. The wizard would not generate any columns. I never determined what caused the problem. I eventually had to reinstall VS 2005 and it started working.
CodeWiz51 -- Life is not a spectator sport. I came to play. Code's Musings | Code's Articles