情况是这样的.
ADO操作SQL数据库 用查询语句的时候,一切正常,但是将查询语句改成了添加或者更新语句,编译无错误,一运行,点击按钮报错abnormal program termination!
虽然报错,但是进入数据库查看数据,发现SQL 添加\更新语句仍然执行成功.
所以很不理解这是什么原因造成的. 网上说是什么野指针..我是菜鸟完全不懂啊, 请各位朋友帮忙看看 谢谢代码如下(按钮中的)
查询时
____________________________________________
void CAdoDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command)); //pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs";
pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=DK";
pConn->Open("","","",adConnectUnspecified); pRst=pConn->Execute("select id from zh where pwd='fdf'",NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("id"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pCmd.Release();
pRst.Release();
pConn.Release();
CoUninitialize();
}
______________________________________________________
插入\更新时
________________________________________________________
void CAdoDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command)); //pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs";
pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=DK";
pConn->Open("","","",adConnectUnspecified);
try{
pRst=pConn->Execute("UPDATE kkk SET pwd = '500' WHERE idd = 'as'",NULL,adCmdText);
}
catch (CException* e) {
char buf[2048];
e->GetErrorMessage(buf, 2048);
e->Delete();
::AfxMessageBox(buf);
}
pRst->Close();
pConn->Close();
pCmd.Release();
pRst.Release();
pConn.Release();
CoUninitialize();
}
ADO操作SQL数据库 用查询语句的时候,一切正常,但是将查询语句改成了添加或者更新语句,编译无错误,一运行,点击按钮报错abnormal program termination!
虽然报错,但是进入数据库查看数据,发现SQL 添加\更新语句仍然执行成功.
所以很不理解这是什么原因造成的. 网上说是什么野指针..我是菜鸟完全不懂啊, 请各位朋友帮忙看看 谢谢代码如下(按钮中的)
查询时
____________________________________________
void CAdoDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command)); //pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs";
pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=DK";
pConn->Open("","","",adConnectUnspecified); pRst=pConn->Execute("select id from zh where pwd='fdf'",NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("id"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pCmd.Release();
pRst.Release();
pConn.Release();
CoUninitialize();
}
______________________________________________________
插入\更新时
________________________________________________________
void CAdoDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command)); //pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs";
pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=DK";
pConn->Open("","","",adConnectUnspecified);
try{
pRst=pConn->Execute("UPDATE kkk SET pwd = '500' WHERE idd = 'as'",NULL,adCmdText);
}
catch (CException* e) {
char buf[2048];
e->GetErrorMessage(buf, 2048);
e->Delete();
::AfxMessageBox(buf);
}
pRst->Close();
pConn->Close();
pCmd.Release();
pRst.Release();
pConn.Release();
CoUninitialize();
}
解决方案 »
- 无线核心网和固网核心网哪个好一点?
- 谁有CAsyncSocket类传文件的例子?大家共同学习!
- 下列函数中的new函数问题
- 问个SQL语句写法
- 编的程序一运行出现警告对话框---说该内存不能为写,请高手综合分析一下原因以及解决方法!!
- 想探求关于重载的含义??!!
- VARIANT怎样转换成CString型的
- 属性页问题!急!!!
- 好像这个问题还没有人问过,ACCESS不支持存储过程,但是简单的可以用ACCESS自己的查询代替吧,那么VC中DAO如何调用ACCESS的查询呢?
- 关于VC中的资源使用问题。(WINDOW编程)
- 高分求救:如何识别一张图片的颜色是cmyk,并把它转换成rgb模式的jpeg图片
- Win32 FONT 图形API中有类似 CFont 的Detach() 函数吗?
把所有的释放_commandptr的语句删掉。