Link to home
Start Free TrialLog in
Avatar of izakref
izakref

asked on

VC ADO CreateParameter

Hi
Is there any way to work under VC++ with CreateParameter without give the parameters hardcoded (to dinamicly sent parameter to StoreProcedure).
Izak
ASKER CERTIFIED SOLUTION
Avatar of missionImpossible
missionImpossible

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ambience
listening ..
Avatar of ccaprar
ccaprar

You have 2 options when working with ADO, and it doesn't matter if it is from VC++ or VB or something else.
1) you issue first a command->Parameters->Refresh() call and from there on you just set the values of the parameters, because the parameters collection is already created
2) you know exactly the order and number of the required srtored procedure parameters ( there can be optional parameters to an SP, and they don't have to be specified in ADO command ), and you issue command->CreateParameter() calls for each parameter and in the correct order

Hope this clears teh things a little,
Cri
izakref will You happy with:

   szSQL=(LPTSTR)malloc(255);
   wsprintf((LPTSTR)szSQL,"exec sp_CreateUser @username='%s', @userpassword='%s', @withupdate=1",m_strUserName,m_strPassword);

using connection:

   pConnection.CreateInstance(__uuidof(Connection));
pConnection->Open((_bstr_t) "DRIVER={SQL Server};UID=blabla;PWD=1234;SERVER=SUPER;DATABASE=LARGE","","",NULL);
pConnection->Execute((_bstr_t) szSQL,NULL,adCmdText);
pConnection->Close();

using recordset, when You need output results:

pRecSet.CreateInstance(__uuidof(Recordset));
//select data from SQL server
pRecSet->Open(  (const _variant_t &) szSQL
            , (const _variant_t &) "DRIVER={SQL Server};UID=blabla;PWD=1234;SERVER=SUPER;DATABASE=LARGE"            , adOpenForwardOnly
            , adLockBatchOptimistic
            , adCmdText);

just dynamically creae szSQL, and go!

good luck!
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "missionImpossible" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner