不好意思,回答错了,我看成是另一个问题了!
有多种方法访问数据库:
ADO方式或OLEDB,给你个OLEDB范例吧
BOOL CDataTableFactory::GetCompDataTable( CEnterpriseInfoVector* pRetVector, LPTSTR strQuery )
{
CDataSource db;
CSession session;
HRESULT hr;
CCommand
hr = db.OpenFromInitializationString( m_strConnection );
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
return FALSE;
hr = session.Open(db);
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
return FALSE;
hr = command.Open(session, strQuery);
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
return FALSE;
while (command.MoveNext() == S_OK)
{
auto_ptr
item->CurrentState = DataEntity::RSINITIAL;
pRetVector->Add( item.release() );
}
command.Close();
session.Close();
db.Close();
return TRUE;
}