功能描述:點擊按鈕,連接資料庫,顯示資料庫中記錄;!-------問題--------!:現編譯通過,無問題,但點擊按鈕時,軟體提示“this application has requested the runtime to terminate it in an unusual way”
主要代碼如下:
[code=c++]
void CAdoDlg::OnBtnQuery()
{
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn.CreateInstance("ADODB.Connection");
pConn->Open("Provider=Microsoft.Jet.OlEDB.4.0;Data Source=d:\bit.mdb","","",adConnectUnspecified);
pRst=pConn->Execute("select * from One",NULL,adCmdText);
//讀取資料庫內容并顯示在“IDC_LIST1”控制元件內
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("v_lname"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
[/code]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/107099.html
標籤:數據庫及相關技術
