Solved

VC ADO CreateParameter

Posted on 2001-06-28
5
587 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 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