CoInitialize(NULL);
_ConnectionPtr pMyConnect=NULL;
HRESULT hr=pMyConnect.CreateInstance(__uuidof(Connection));
if(FAILED(hr))return;
_bstr_t strConnect="Provider=SQLOLEDB; Server=7BWZ82X-XP-CN//sqlexpress;"
"Database=wx; uid=sa; pwd=123456;";
//connecting to the database server now:
try{pMyConnect->Open(strConnect,"","",NULL);}
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),_T("警告"),MB_OK|MB_ICONWARNING);
}
_CommandPtr pCmd = NULL;
_RecordsetPtr pRecordset = NULL;
pCmd.CreateInstance(__uuidof(Command));
pRecordset.CreateInstance(_uuidof(Recordset));
pCmd->ActiveConnection = pMyConnect;
pCmd->CommandType = adCmdStoredProc;
pCmd->CommandText=_bstr_t(_T("Login")); //SP Name
pCmd->Parameters->Refresh();
char chId[65];
sprintf(chId,"%ld", time(0));
pCmd->Parameters->GetItem((long)1)->Value = _variant_t(4);
pCmd->Parameters->GetItem((long)2)->Value = _variant_t("44");
/*pRecordset = */pCmd->Execute(NULL,NULL,adCmdStoredProc);
//pRecordset.Release();
_variant_t v= pCmd->Parameters->GetItem((long)0)->Value;
CString str;
str.Format(_T("%d"), v.intVal);
MessageBox(str);
v= pCmd->Parameters->GetItem((long)3)->Value;
str;
str.Format(_T("%d"), v.intVal);
MessageBox(str);
pCmd.Release();
pMyConnect.Release();
CoUninitialize();
ado调用存储过程(带输出参数)
最新推荐文章于 2022-05-27 10:01:24 发布