Click here to Skip to main content
15,897,334 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSetting Current Directory Pin
Andy Latham15-May-02 0:40
Andy Latham15-May-02 0:40 
GeneralRe: Setting Current Directory Pin
Nish Nishant15-May-02 1:12
sitebuilderNish Nishant15-May-02 1:12 
GeneralRe: Setting Current Directory Pin
Prem Kumar15-May-02 2:27
Prem Kumar15-May-02 2:27 
GeneralRe: Setting Current Directory Pin
Andy Latham15-May-02 2:37
Andy Latham15-May-02 2:37 
GeneralRe: Setting Current Directory Pin
Prem Kumar15-May-02 3:41
Prem Kumar15-May-02 3:41 
GeneralModal dialog closing problem Pin
Patrick Riphagen15-May-02 0:21
Patrick Riphagen15-May-02 0:21 
GeneralRe: Modal dialog closing problem Pin
Nish Nishant15-May-02 0:28
sitebuilderNish Nishant15-May-02 0:28 
QuestionHow can extract a Return Value from a Stored Procedure with ADO Pin
youssef14-May-02 23:48
youssef14-May-02 23:48 
Hi,

I use a stored procedure for write to a Database.
When I execute the Stored Procedure, this Stored Procedure acknoledge with a int value if all are OK.

I would like to know how can I do for reading this value.
The value must be extract from the "Status".

You find my sample code:


//Initialize the connection with the Database RTLSQL1 ARCHIVES_NUM
//COM initialization
CoInitialize (NULL);
_ConnectionPtr m_pConn2("ADODB.Connection");
_ParameterPtr pParam2,pParam3;

try
{
//Check if I can create a instance for a connection into a db
HRESULT hr = m_pConn2.CreateInstance (__uuidof (Connection));

if (FAILED (hr))
{
// Automat_LOG_WITH_TIME(_T("DB : Can't create intance of Connection"));
}
else
{
// Automat_LOG_WITH_TIME(_T("DB : I can create intance of Connection"));
}

CString strFileName = "JA001206";
//Check if I can Open a session in the RTLSQL1 ARCHIVES_TVI
if (FAILED (m_pConn2->Open("provider=sqloledb.1;database=ARCHIVES_TVI;server=1.1.1.1;uid=Automat;pwd=Automat;network=dbmssocn","","",adConnectUnspecified)))

{
// Automat_LOG_WITH_TIME(_T("DB : Can't open datasource "));
// Automat_Send_SMS(_T("DB : Can't open datasource "),_T(""));

}
else
{
//Automat_LOG_WITH_TIME(_T("DB : I can open datasource "));
CString sT;
sT.Format("%d",1);
_variant_t varLiReturn;
int liReturn = -99;

_CommandPtr pCmd2("ADODB.Command");
pCmd2->ActiveConnection = m_pConn2;
//Store procedure for the DATABASE
pCmd2->CommandText = "StartFileNumV3";

pParam2 = pCmd2->CreateParameter ( _bstr_t ("FileName"), adVarChar,
adParamInput, strFileName.GetLength (), (_bstr_t) strFileName);
pCmd2->Parameters->Append ( pParam2);


pParam2 = pCmd2->CreateParameter ( _bstr_t ("AutomatNr"), adInteger,
adParamInput, sizeof(int), _variant_t (sT));

pCmd2->Parameters->Append ( pParam2);
pParam2 = pCmd2->CreateParameter(_T("Status"),adInteger,adParamOutput,sizeof(int),varLiReturn);
pCmd2->Parameters->Append ( pParam2);

_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset = pCmd2->Execute(NULL, NULL, adCmdStoredProc);
//******************
//!!!!!!!! I don't know if it is correct to receive the return value
varLiReturn = pCmd2->Parameters->Item[_T("Status")]->Value;

Sleep(100); //ms
//Automat_LOG_WITH_TIME(_T("DB : The Store Procedure have been execute with success (StartFileNum)"));

//Close the DATABASE
if ( (m_pConn2->State & adStateOpen) == adStateOpen)
{
m_pConn2->Close();
// Automat_LOG_WITH_TIME(_T("DB : I can close datasource RTLSQL1 ARCHIVES_TVI"));
}
else
{
// Automat_LOG_WITH_TIME(_T("DB : I can't close datasource RTLSQL1 ARCHIVES_TVI"));
}
}
}
catch ( _com_error &e )
{
_bstr_t bstrSource (e.Source());
_bstr_t bstrDescription (e.Description());
CString sErrorDB;
sErrorDB.Format("DB : ERROR !!!!!\r\nException thrown for classes generated by #import\r\nCode = %08lx\r\nCode meaning = %s\r\nSource = %s\r\nDescription = %s\r\n", e.Error (), e.ErrorMessage (), (LPCTSTR) bstrSource, (LPCTSTR) bstrDescription);
// Automat_LOG_WITH_TIME(sErrorDB);
MessageBox (sErrorDB, bstrDescription,MB_OK);
}
catch (...)
{
TRACE ( "*** Unhandled Exception ***" );
}

Sleep(100); //ms
CoUninitialize();

youssef
AnswerRe: How can extract a Return Value from a Stored Procedure with ADO Pin
Jon Hulatt14-May-02 23:54
Jon Hulatt14-May-02 23:54 
GeneralRe: How can extract a Return Value from a Stored Procedure with ADO Pin
youssef15-May-02 2:52
youssef15-May-02 2:52 
GeneralRe: How can extract a Return Value from a Stored Procedure with ADO Pin
Jon Hulatt15-May-02 3:08
Jon Hulatt15-May-02 3:08 
GeneralRe: How can extract a Return Value from a Stored Procedure with ADO Pin
Carlos Antollini15-May-02 3:27
Carlos Antollini15-May-02 3:27 
GeneralRe: How can extract a Return Value from a Stored Procedure with ADO Pin
Jon Hulatt15-May-02 5:14
Jon Hulatt15-May-02 5:14 
GeneralRe: How can extract a Return Value from a Stored Procedure with ADO Pin
Carlos Antollini15-May-02 5:27
Carlos Antollini15-May-02 5:27 
GeneralRe: How can extract a Return Value from a Stored Procedure with ADO Pin
Jon Hulatt15-May-02 5:38
Jon Hulatt15-May-02 5:38 
GeneralRe: How can extract a Return Value from a Stored Procedure with ADO Pin
Carlos Antollini15-May-02 5:48
Carlos Antollini15-May-02 5:48 
GeneralRe: How can extract a Return Value from a Stored Procedure with ADO Pin
Jon Hulatt15-May-02 5:46
Jon Hulatt15-May-02 5:46 
GeneralThreads and server side applications Pin
unknown soldier14-May-02 23:44
unknown soldier14-May-02 23:44 
GeneralRe: Threads and server side applications Pin
Nish Nishant14-May-02 23:55
sitebuilderNish Nishant14-May-02 23:55 
GeneralRe: Threads and server side applications Pin
unknown soldier15-May-02 0:01
unknown soldier15-May-02 0:01 
GeneralMulti-language Pin
14-May-02 23:43
suss14-May-02 23:43 
GeneralRe: Multi-language Pin
Christian Graus15-May-02 3:03
protectorChristian Graus15-May-02 3:03 
GeneralRe: Multi-language Pin
Paul M Watt15-May-02 8:27
mentorPaul M Watt15-May-02 8:27 
GeneralRe: Multi-language Pin
15-May-02 22:57
suss15-May-02 22:57 
GeneralHelp................................ Pin
johny quest14-May-02 23:26
johny quest14-May-02 23:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.