
关于MFC连接到数据库(ADO)。。。。
代码:CoInitialize(NULL);_ConnectionPtrpConn(__uuidof(Connection));_ConnectionPtrpConn2(...
代码:
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_ConnectionPtr pConn2(__uuidof(Connection));
_RecordsetPtr pRset2(__uuidof(Recordset));
_RecordsetPtr pRset(__uuidof(Recordset));
pConn->ConnectionString = CONNECTIONSTRING;
pConn->Open("","","",adConnectUnspecified);
pRset = pConn->Execute("select * from 新注册用户",NULL,adCmdText);
pConn2->ConnectionString = CONNECTIONSTRING;
pConn2->Open("","","",adConnectUnspecified);
pRset2 = pConn2->Execute("select * from 卖家",NULL,adCmdText);
while(!pRset->rsEOF)
{
if(m_sName == (char*)(_bstr_t)pRset->GetCollect("用户名"))
{
MessageBox("用户名已被使用","提示",MB_OK|MB_ICONWARNING);
return;
}
pRset->MoveNext();
}
if(pRset->rsEOF)
{
while(!pRset2->rsEOF)
{
if(m_sName == (char *)(_bstr_t)pRset2->GetCollect("用户名") )
{
MessageBox("用户名已被使用","提示",MB_OK|MB_ICONWARNING);
return;
}
pRset2->MoveNext();
}
if(pRset2->rsEOF)
{
pRset->AddNew();
pRset->PutCollect("注册身份",_variant_t("卖家"));
pRset->PutCollect("用户名",_variant_t(m_sName));
pRset->PutCollect("密码",_variant_t(m_sKeyword1));
pRset->PutCollect("是否已审核",_variant_t("No"));
pRset->Update();
}
// pRset2->close();
// pConn2->close();
pRset2.Release();
pConn2.Release();
}
// pRset->close();
// pConn->close();
pRset.Release();
pConn.Release();
CoUninitialize();
OnOK();
主要是实现用户注册,但是要保证之前在注册的新用户和卖家表中都没有该用户名,然后才能向“新注册用户”表中添加数据。
程序编译、连接都没有问题。。。。
但是在运行时会意外中止。。。。
麻烦看看啦~~~~
QQ:522563153
已经Deburg过了。。。就是AddNew()的错误。。。而且pRset好像指向数据库的末尾。。不管进行什么操作,想Move都会出现同样的错误。。。。麻烦再看看啦~~~ 展开
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_ConnectionPtr pConn2(__uuidof(Connection));
_RecordsetPtr pRset2(__uuidof(Recordset));
_RecordsetPtr pRset(__uuidof(Recordset));
pConn->ConnectionString = CONNECTIONSTRING;
pConn->Open("","","",adConnectUnspecified);
pRset = pConn->Execute("select * from 新注册用户",NULL,adCmdText);
pConn2->ConnectionString = CONNECTIONSTRING;
pConn2->Open("","","",adConnectUnspecified);
pRset2 = pConn2->Execute("select * from 卖家",NULL,adCmdText);
while(!pRset->rsEOF)
{
if(m_sName == (char*)(_bstr_t)pRset->GetCollect("用户名"))
{
MessageBox("用户名已被使用","提示",MB_OK|MB_ICONWARNING);
return;
}
pRset->MoveNext();
}
if(pRset->rsEOF)
{
while(!pRset2->rsEOF)
{
if(m_sName == (char *)(_bstr_t)pRset2->GetCollect("用户名") )
{
MessageBox("用户名已被使用","提示",MB_OK|MB_ICONWARNING);
return;
}
pRset2->MoveNext();
}
if(pRset2->rsEOF)
{
pRset->AddNew();
pRset->PutCollect("注册身份",_variant_t("卖家"));
pRset->PutCollect("用户名",_variant_t(m_sName));
pRset->PutCollect("密码",_variant_t(m_sKeyword1));
pRset->PutCollect("是否已审核",_variant_t("No"));
pRset->Update();
}
// pRset2->close();
// pConn2->close();
pRset2.Release();
pConn2.Release();
}
// pRset->close();
// pConn->close();
pRset.Release();
pConn.Release();
CoUninitialize();
OnOK();
主要是实现用户注册,但是要保证之前在注册的新用户和卖家表中都没有该用户名,然后才能向“新注册用户”表中添加数据。
程序编译、连接都没有问题。。。。
但是在运行时会意外中止。。。。
麻烦看看啦~~~~
QQ:522563153
已经Deburg过了。。。就是AddNew()的错误。。。而且pRset好像指向数据库的末尾。。不管进行什么操作,想Move都会出现同样的错误。。。。麻烦再看看啦~~~ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询