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

x
?
Solved

a very basic question

Posted on 2003-10-31
4
Medium Priority
?
241 Views
Last Modified: 2010-04-02
the following is a bit of the code iam using! to access a database.
ConStr[0] = '\0';
strcat(ConStr, "SELECT * FROM prodlist WHERE product_name = 'aegis 1.0'");
pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1);

Now I want to assign it to another variable and then use the variable in place of 'aegis 1.0'.
to what variable should i assign it??

0
Comment
Question by:jiljil
[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
4 Comments
 

Author Comment

by:jiljil
ID: 9657137
.....
0
 
LVL 32

Accepted Solution

by:
jhance earned 60 total points
ID: 9657235
1) there is no need to use strcat() as you have.  You can simply do:

pRecordset = m_pConnection->Execute("SELECT * FROM prodlist WHERE product_name = 'aegis 1.0'", vRecordsAffected, 1);

Much less confusing if you are using "static" strings in your SQL.

2) To use a VARIABLE string, use a FORMATTED string.  One way is:

sprintf(ConStr, "SELECT * FROM prodlist WHERE product_name = '%s'", lpszVar);
pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1);

If you have the value you want instead of "aegis 1.0" in the lpszVar variable, the sprintf function will "fill in" the %s with that.

There are MANY other ways as well, and I'm sure someone will point them out.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10546351
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: jhance {http:#9657235}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

610 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