关于数据库链的问题
CoInitialize(NULL);try
{
m_pConn.CreateInstance("ADODB.Connection");
m_pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=red.mdb;Persist Security Info=False";
m_pConn->Open("","","",adConnectUnspecified);
}
catch(_com_error e)
{
::CoUninitialize();
::AfxMessageBox(e.ErrorMessage());
//return false;
}
我想把上面红色的代码放到**App类中的InitInstance()函数,那面在使用下面代码时,怎么引用m_pConn这个变量?
m_pRs.CreateInstance("ADODB.Recordset");
m_pRs->Open((_variant_t)("select * from admin"),
_variant_t((IDispatch *)m_pConn,true),
adOpenStatic,adLockOptimistic,adCmdText);
if((passworc)==0)
{
m_pRs->AddNew();
m_pRs->PutCollect("username",_variant_t(username));
m_pRs->PutCollect("password",_variant_t(password));
m_pRs->Update();
MessageBox("注册成功!");
}
else
{
MessageBox("两次输入密码不一致");
}