Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VC ADO CreateParameter

Posted on 2001-06-28
5
Medium Priority
?
604 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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

609 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