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("AddUser")); //SP Name
pCmd->Parameters->Refresh();
char chId[65];
sprintf(chId,"%ld", time(0));
pCmd->Parameters->GetItem((long)1)->Value = _variant_t(chId);
pCmd->Parameters->GetItem((long)2)->Value = _variant_t("chId");
//pCmd->Parameters->Item[_variant_t(_bstr_t("@loginName") )]->Value=_variant_t(chId);
//pCmd->Parameters->Item[_variant_t(_bstr_t("@passWord") )]->Value=_variant_t("DD");
/*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);
pCmd.Release();
pMyConnect.Release();
CoUninitialize();
vc2010调用存储过程
最新推荐文章于 2021-04-16 04:54:51 发布