Solved

a very basic question

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now