• 全部
...

_RecordsetPtr

ji_angwen 2010-04-29 12:15:47
void CMyDlg::OnOK()
{
// TODO: Add extra validation here
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst=(__uuidof(RecordsetPtr));

pConn->ConnectionString="Driver={MYSQL ODBC 5.1 Driver};Server=localhost;Database=jiang;User=root;Password=jiang;Option=3";
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute("select *from login",NULL,adCmdText);


CString str1,str2,str3;
GetDlgItem(IDC_EDIT1)->GetWindowText(str1);

while(!pRst->rsEOF)
{

if(str1==(_bstr_t)pRst->GetCollect("UserName"))
{
MessageBox("该用户名已存在!");
return;
}

pRst->MoveNext();
}
GetDlgItem(IDC_EDIT2)->GetWindowText(str2);
GetDlgItem(IDC_EDIT3)->GetWindowText(str3);

if(str2!=str3)
{
MessageBox("密码不一致!");
return;
}
else
{
pRst->AddNew();
pRst->PutCollect("UserName",_variant_t(str2));
pRst->PutCollect("UserName",_variant_t(str3));
pRst->Update();
}



pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
MessageBox("注册成功!");


CDialog::OnOK();



}
调试的时候运行到pRst->AddNew();时出错,,,,
...全文
给本帖投票
286 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiangorqiang 2010-04-29
  • 打赏
  • 举报
回复
用通过
pRst-->Open("select *from login",_vatiant_t((IDispatch *)pConn,true),adOpenDynamic,adLockOptimistic,adCmdText);
这种方式打开才能编辑。
Execute返回的是只读记录集。
ji_angwen 2010-04-29
  • 打赏
  • 举报
回复
呵呵,解决了
qiangorqiang 2010-04-29
  • 打赏
  • 举报
回复
看不到图。
尹成 2010-04-29
  • 打赏
  • 举报
回复
用通过
pRst-->Open("select *from login",_vatiant_t((IDispatch *)pConn,true),adOpenDynamic,adLockOptimistic,adCmdText);
这种方式打开才能编辑。
Execute返回的是只读记录集
ji_angwen 2010-04-29
  • 打赏
  • 举报
回复
ji_angwen 2010-04-29
  • 打赏
  • 举报
回复
qiangorqiang 2010-04-29
  • 打赏
  • 举报
回复
login表是怎么定义的?
ji_angwen 2010-04-29
  • 打赏
  • 举报
回复
现在运行到pRst->Update();的时候出错,,,,,,
ji_angwen 2010-04-29
  • 打赏
  • 举报
回复
现在运行到pRst->Update();的时候出错,,,,,,
ji_angwen 2010-04-29
  • 打赏
  • 举报
回复
把原程序改为下面这样:

void CHeheDlg::OnOK()
{
// TODO: Add extra validation here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pRst.CreateInstance(" ");
pConn->ConnectionString="Driver={MYSQL ODBC 5.1 Driver};Server=localhost;Database=jiang;User=root;Password=jiang;Option=3";
pConn->Open("","","",adConnectUnspecified);
pRst->Open("select *from login",_variant_t((IDispatch *)pConn,true),adOpenDynamic,adLockOptimistic,adCmdText);





CString str1,str2,str3;
GetDlgItem(IDC_EDIT1)->GetWindowText(str1);

while(!pRst->rsEOF)
{

if(str1==(_bstr_t)pRst->GetCollect("UserName"))
{
MessageBox("该用户名已存在!");
return;
}

pRst->MoveNext();
}
GetDlgItem(IDC_EDIT2)->GetWindowText(str2);
GetDlgItem(IDC_EDIT3)->GetWindowText(str3);

if(str2!=str3)
{
MessageBox("密码不一致!");
return;
}
else
{
pRst->AddNew();
pRst->PutCollect("UserName",_variant_t(str2));
pRst->PutCollect("UserName",_variant_t(str3));
pRst->Update();
}



pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
MessageBox("注册成功!");


CDialog::OnOK();



}
运行到pRst->Update();的时候出错
tanwei1002 2010-04-29
  • 打赏
  • 举报
回复
捕获异常看看是什么问题
ljz888666555 2010-04-29
  • 打赏
  • 举报
回复
try
{}
catch(_com_error &e)
{}
看报的什么错。

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧

手机看
关注公众号

关注公众号

客服 返回
顶部