In VC ++, use ADO to perform SQL Server stored procedures, and obtain an example of return value

xiaoxiao2021-03-06  43

_variant_t RecordsAffected; string szSql = (string) "P_KS_ADDUSER '" m_szName "', '" m_szPasswd "';"; try {_CommandPtr ptrCmd; ptrCmd.CreateInstance (__ uuidof (Command)); ptrCmd-> ActiveConnection = pContext- > GetConnection ();

Variant vtroyalty;

Vtroyalty = Colevariant ((long) 0); ptrcmd-> parameters-> append (PTRCMD-> CreateParameter ("Return", Adinteger, AdParamreturnValue, Sizeof (int), vtroyalty);

Vtroyalty = Colevariant (m_szname.c_str ()); ptrcmd-> parameters-> append (ptrcmd-> createparameter ("name", adchar, adparaminput, m_szname.size (), vtroyalty));

Vtroyalty = Colevariant (m_szpasswd.c_str ()); ptrcmd-> parameters-> append (ptrcmd-> createparameter ("pass", adchar, adparaminput, m_szpasswd.size (), vtroyalty));

PTRCMD-> CommandText = "p_ks_adduser"; ptrcmd-> commandtype = adcmdstoredProc; ptrcmd-> execute (null, null, adcmdstoredProc);

Cout << "Add user success, id =" << (unsigned int) PTRCMD-> parameters-> GetItem ("return") -> getValue () << Endl; // cout << "add ID: << (unsigned int) PTRCMD-> getParameters () -> GetItem (0) << endl; // pcontext-> getNetwork Shense () -> sendpack ();} catch (_EROR E) {cout << "Increase users Abnormal: "<< (LPCSTR) E.Description () << Endl; Return;} If there are multiple values ​​to return, then the output parameter (Output parameter) can be used; if you need to return an array, you can use the return data Method of set.

转载请注明原文地址:https://www.9cbs.com/read-54869.html

New Post(0)