代码如下
void CBnnnnDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset)); pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False";
pConn->Open("","","",adConnectUnspecified); pRst=pConn->Execute("select * from student",NULL,adCmdText); while (!pRst->adoEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("names"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();}按下Button1提示Runtime Error! Program:d:\text\bnnnn\Debug\bnnnn.exe This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
我下断点调试,好像是
pConn->Open("","","",adConnectUnspecified);
这行出错了!!但是我不会改……
void CBnnnnDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset)); pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False";
pConn->Open("","","",adConnectUnspecified); pRst=pConn->Execute("select * from student",NULL,adCmdText); while (!pRst->adoEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("names"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();}按下Button1提示Runtime Error! Program:d:\text\bnnnn\Debug\bnnnn.exe This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
我下断点调试,好像是
pConn->Open("","","",adConnectUnspecified);
这行出错了!!但是我不会改……
解决方案 »
- 高分求!!!YUY2数据格式转换为RGB24的数据格式的方法?
- 来者有分,菜鸟问题。
- 为什么用同样的方式,将同一个.h文件,添加到不同的工程里,有的编译时,会出现#include ".h"文件出错呢?
- 在控制台程序,怎么引入ADO数据库接口
- 请教:如何用Win32 API 取系统用户的账号信息啊?
- 在DEBUG模式下编译正常,但在Realese模式编译出错提示fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 17
- 如何在CView中显示指定文本文件!(急~~~~~~~!)
- 寻找源程序!
- 请问开机后自动启动的程序写在注册表的哪个位置???拜托了
- 我的华为梦!
- 截获控件消息
- 关于设置SOCK接收发送超时
m_pCon->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=XX.mdb","","",adModeUnknown);
pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False","","",adModeUnknown);不管用啊,还是那个提示~
如果我运行DEBUG文件夹下的那个程序就没有这个提示,可以正常访问!
最后参数adModeUnknown换为edCmdText或者adCmdUnknown试试!
获取数据库操作的异常信息
void CBnnnnDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset)); //pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False";
try
{
pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False","","",adModeUnknown);
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("数据库连接失败!\r \n 错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
pRst=pConn->Execute("select * from student",NULL,adCmdText);
while (!pRst->adoEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("names"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();}
加入了捕捉错误代码~但是提示的是“未指定的错误”~~晕~~
try{
pConn->Open("","","",adConnectUnspecified);
}
catch(_com_error& e)
{
CString strValue;
strValue.Format(_T("%s"),(LPCTSTR)e.Description());
AfxMessagebox(strValue);
}看看什么错误,有可能是找不到数据库文件,你应该在数据库文件路径哪里动态获取绝对路径