?
Solved

a very basic question

Posted on 2003-10-31
4
Medium Priority
?
236 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

Industry Leaders: 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

766 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