Database programming transcript

xiaoxiao2021-03-06  67

After getting the ADO introduction, I tried to call the stored procedure in a Command mode. The stored procedure is mainly based on the input parameters, and there is a complex query statement, so returns a recordset, and the stored procedure itself has a return parameter. The procedure is as follows:

{_CommandPtr cmmd; _ParameterPtr param; HRESULT hr = cmmd.CreateInstance (__ uuidof (Command)); ( "Create GetShipTrack () in _CommandPtr object failed") if (FAILED (hr)) {AfxMessageBox; return false;} cmmd-> ActiveConnection = m_piConnection; ADO // requires connection cmmd-> CommandType = adCmdStoredProc; cmmd-> CommandText = _bstr_t ( "GetShipTrack"); param = cmmd-> CreateParameter ( "", adChar, adParamInput, shipTrackInfo.sMMSIID.GetLength ( ) 1, _variant_t (shiptrackinfo.smms); cmmd-> parameters-> append (param); param = cmmd-> createparameter (", adtinyint, adparaminput, sizeof (byte), (byte) bshowais; cmmd- > Parameters-> append (param); param = cmmd-> createparameter ("@ Ret", Adchar, AdParamReturnValue, 1); cmmd-> parameters-> append (param); _Recordset * prec = 0; HRESULT HR1; HR1 = Cmmd-> Raw_execute (null, null, adcmdstoredProc, & prec); if (Failed (HR1)) {AFXMessageBox ("Get ship trajectory information failed! "); Return false;} _recordsetptr pirecordset; pirecordset = _recordsetptr (PREC, FALSE);

The problem is coming, no matter whether it is RAW_EXECUTE or Execute Returns a record set, it is not possible to get the value returned to the parameter @ret, which is always VT_EMPTY. Believe me, there is no error in the stored procedure. I will definitely set the correct value for @ret. The same situation, another stored procedure is inserted into a message. There is also a return value @ret, the program is as follows:

{_CommandPtr cmmd; _ParameterPtr param; HRESULT hr = cmmd.CreateInstance (__ uuidof (Command)); if (FAILED (hr)) {g_ErrLog.WriteErrorInfo ( "AddAISDynamicInfo", "create object fails _CommandPtr"); return false;} cmmd -> ActiveConnection = m_piConnection; ADO // requires connection cmmd-> CommandType = adCmdStoredProc; cmmd-> CommandText = _bstr_t ( "AddAISDynamicInfo"); param = cmmd-> CreateParameter ( "", adChar, adParamInput, sMsgData15.sMMSINum. GetLength () 1, _variant_t (sMsgData15.sMMSINum)); cmmd-> Parameters-> Append (param); param = cmmd-> CreateParameter ( "", adTinyInt, adParamInput, sizeof (BYTE), sMsgData15.byNavStatus); cmmd -> parameters-> append (param); param = cmmd-> CreateParameter (", addouble, adpaaminput, sizeof (float), smsgdata15.fsog); Cmmd-> parameters-> append (param); param = cmmd-> createparameter (", addouble, adpaaminput, sizeof); cmmd-> parameters-> append (param); param = cmmd- > CreateParameter ("", addouble, adparaminput, sizeof (float) smsgdata15.chrot; cmmd-> parameters-> append (param); param = cmmd-> createparameter (", addouble, adparaminput, sizeof Double), smsgdata15.dlong); cmmd-> parameters-> append (param); param = cmmd->

CreateParameter (", addouble, adparaminput, sizeof (double), smsgdata15.dlat; cmmd-> parameters-> append (param); param = cmmd-> CreateParameter (", ADTINYINT, ADPARAMINPUT, SIZEOF (Byte), BYTE) (SMSGDATA15.BPOSACU); cmmd-> parameters-> append (param); param = cmmd-> createparameter (", Adsmallint, Adparaminput, Sizeof (Word), SMSGData15.WtrueHeading; cmmd-> Parameters-> append (param); long nok = 0; param = cmmd-> CreateParameter ("CreturnVal", Adbigint, AdParamoutput, Sizeof (long), _VARIANT_T (NOK)); cmmd-> parameters-> append (param); CMMD-> EXECUTE (NULL, NULL, ADCMDSTOREDPROC); VRETURN = Cmmd-> parameters-> GetItem ("CreturnVal") -> getValue (); // By parameter return value nok = (long) vreturn; but then return The value is correct. NOK is 1

I didn't understand why I would like this. Is there a return parameter that has the return parameters if there is a recordset returned? ? ?

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

New Post(0)