舉個例子,連線SQL:
// 開啟資料庫
strDBClass.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password=%s"), m_strUnEntryptMdbFilePath,m_strMDBPassword);
// 建立連線
HRESULT hr = m_pConnection.CreateInstance(_uuidof(Connection));
_ConnectionPtr m_pConnection->Open(m_strDBClass,_T(""),_T(""),adConnectUnspecified);
// 宣告表單指標
_RecordsetPtr pBandRecordset;
pBandRecordset.CreateInstance(__uuidof(Recordset));
// 執行語句
CString strSQL(L"SELECT * FROM [Band]");
m_pConnection->Execute((LPCTSTR)strSQL,NULL,0);
// 提取某一項 例如BandInfo
int iBandInfo = wcscmp(colum, L"BandInfo");
while(!recordsetPtr->adoEOF)
{
var = recordsetPtr->GetCollect(colum);
if(var.vt != VT_NULL)
strName = (LPCSTR)_bstr_t(var);
recordsetPtr->MoveNext();
}
舉個例子,連線SQL:
// 開啟資料庫
strDBClass.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password=%s"), m_strUnEntryptMdbFilePath,m_strMDBPassword);
// 建立連線
HRESULT hr = m_pConnection.CreateInstance(_uuidof(Connection));
_ConnectionPtr m_pConnection->Open(m_strDBClass,_T(""),_T(""),adConnectUnspecified);
// 宣告表單指標
_RecordsetPtr pBandRecordset;
pBandRecordset.CreateInstance(__uuidof(Recordset));
// 執行語句
CString strSQL(L"SELECT * FROM [Band]");
m_pConnection->Execute((LPCTSTR)strSQL,NULL,0);
// 提取某一項 例如BandInfo
int iBandInfo = wcscmp(colum, L"BandInfo");
while(!recordsetPtr->adoEOF)
{
var = recordsetPtr->GetCollect(colum);
if(var.vt != VT_NULL)
strName = (LPCSTR)_bstr_t(var);
recordsetPtr->MoveNext();
}