Solved

VC ADO CreateParameter

Posted on 2001-06-28
5
575 Views
Last Modified: 2008-03-10
Hi
Is there any way to work under VC++ with CreateParameter without give the parameters hardcoded (to dinamicly sent parameter to StoreProcedure).
Izak
0
Comment
Question by:izakref
5 Comments
 
LVL 2

Accepted Solution

by:
missionImpossible earned 100 total points
ID: 6234419
you can do it dynamically with CreateParameter:
When calling storedProcs, only the sequence of the ADO-parameters must fit the sequence of the StoredProc parameters.  What do you mean with 'dynamically'?

isn't this dynamically:
m_spCommand->CreateParameter(bstrName, vtValue.vt, adParamInput, length, vtValue);

0
 
LVL 22

Expert Comment

by:ambience
ID: 6234569
listening ..
0
 
LVL 1

Expert Comment

by:ccaprar
ID: 6236932
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
0
 
LVL 1

Expert Comment

by:guyfromeast
ID: 6258302
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!
0
 
LVL 11

Expert Comment

by:griessh
ID: 6820088
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: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

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

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now