Solved

a very basic question

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

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. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

777 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