I have a Notes table with the structure
CREATE TABLE Notes (
ProviderNo CHAR(9),
Note CHAR(29))
The wizard has created an Accessor class and probably an additional class that is derived from the accessor class. So you should have something like this.
class CDBNotesAccessor
{
public:
CDBNotesAccessor()
{
ClearData();
};
void ClearData()
{
memset( (void*)this, 0, sizeof(*this) );
};
TCHAR m_szProviderNo[10];
TCHAR m_szNote[30];
BEGIN_COLUMN_MAP(CDBNotesAccessor)
COLUMN_ENTRY(1, m_szProviderNo)
COLUMN_ENTRY(2, m_szNote)
END_COLUMN_MAP()
DEFINE_COMMAND(CDBNotesAccessor, _T("SELECT ProviderNo, Note FROM Notes"))
};
class CDBNotes: public CCommand<caccessor><cdbnotesaccessor> >
{
public:
CDBNotes(void);
virtual ~CDBNotes(void);
HRESULT OpenNotes(CDBSession& session)
{
CDBPropSet propset(DBPROPSET_ROWSET);
propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
propset.AddProperty(DBPROP_IRowsetScroll, true);
propset.AddProperty(DBPROP_IRowsetChange, true);
propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE );
hr = CCommand<caccessor><cdbnotesaccessor> >::Open(session, NULL, &propset);
return hr;
}
};
</cdbnotesaccessor></caccessor></cdbnotesaccessor></caccessor>
1. you need to connect to database using ATL:CSession object. Something like this:
ATL::CSession session;
ATL::CDataSource db;
ATL::CDBPropSet dbinit(DBPROPSET_DBINIT);
HRESULT hr;
dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);
dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);
dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "");
dbinit.AddProperty(DBPROP_AUTH_USERID, "Admin");
dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "C:\\my_access_db.mdb");
dbinit.AddProperty(DBPROP_INIT_MODE, (long)16);
dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, "");
dbinit.AddProperty(DBPROP_INIT_TIMEOUT, 60000);
hr = db.OpenWithServiceComponents("Microsoft.Jet.OLEDB.4.0", &dbinit, 1);
if(FAILED(hr))
{
}
hr = session.Open(db)
if(FAILED(hr))
{
}
now, you should have a valid CSession object that is connected to the C:\my_access_db.mdb database. If you use SQL Server then the initialisation parameters will be a bit different (you would have SQL Server name, username and password). Let me know if you need more info on this one.
2. Now, to use the CDBNotes class do this:
CDBNotes notes;
hr = notes.Open(session); if(FAILED(hr))
{
}
while((hr = notes.MoveNext()))
{
cout << notes.m_szProviderNo << notes.m_szNote;
_tcsupr(notes.m_szProviderNo);
hr = notes.SetData()
if(FAILED(hr))
{
}
}
_tcscpy(notes.m_szProviderNo, _T("123"));
_tcscpy(notes.m_szNote, _T("456"));
hr = notes.Insert();
if(FAILED(hr))
{
}
notes.Close();
session.Close();