Solved

VC ADO CreateParameter

Posted on 2001-06-28
5
582 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

770 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