Solved

a very basic question

Posted on 2003-10-31
4
232 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 20 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

Technology Partners: 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…
  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 …
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.

696 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