求救:Runtime error问题
VC6+ADO+SQL SERVER2000
我新建了一个基于对话框的MFC AppWizard[exe]文件,在对话框上新建了一个按钮和一个ListBox,单击此按钮时,ListBox用来显示数据库中的内容。代码如下:
//StdAfx.h中导入动态链接库
...
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF")
...
//AdoDlg.cpp中连接数据库
...
void CAdoDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString="Provider=SQLOLEDB.1;Password=sa;Persist Security Info=TRUE;User ID=sa;Initial Catalog=pubs";
pConn->Open(" "," "," ",adConnectUnspecified);
pRst=pConn->Execute("select au_lname from authors",NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("au_lname"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
...
程序在编译链接时都没有错误,但是运行后,当单击按钮时,程序就出现一个报错对话框,报错内容如下:
Runtime Error!
Program:E:\VC6.0\Ado\Debug\Ado.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
难道是还有什么地方没有做吗?谢谢大家帮我解答。