pRst=pConn->Execute(pipei,NULL,adCmdText);
如果搜不到则pRst->rsEOF为1;若有记录集,则pRst->rsEOF为0!
stdafx.h最后一个#endif前添加:
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF")
按钮函数中:
UpdateData();
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString ="Provider=SQLOLEDB.1;Password=12345sa12345;Persist Security Info=True;User ID=sa;Initial Catalog=DBLAB;Data Source=STAR-PC;";
pConn->Open ("","","",adConnectUnspecified);
//cstring.format
CString str = "select * from dbo.userinfo where userName = '2' and userPwd = '1'";
_bstr_t pipei = (_bstr_t)str;
pRst=pConn->Execute(pipei,NULL,adCmdText);
if(!pRst->rsEOF)//pRst->rsEOF的值判定是否到达结尾,到达则为真,未到达则为假
{
MessageBox("yeah!");
}
else
MessageBox("登录失败!");
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();