-
October 31st, 2003, 07:49 AM
#1
a very basic question
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??
sriranjani
-
October 31st, 2003, 07:58 AM
#2
String manipulation
SJ,
Are you using the C++ language? If so, then I recommend using standard template library strings (STL strings) for these kinds of string manipulations.
The STL strings make it very easy to manipulate strings.
Look at the following example:
Code:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
string control = "SELECT * FROM prodlist WHERE product_name = ";
string selection = "aegis 1.0";
cout << control + selection << endl;
return 0;
}
Good luck.
Sincerely, Chris.
You're gonna go blind staring into that box all day.
-
October 31st, 2003, 08:00 AM
#3
You are much better off using stringstreams:
std::stringstream query;
query << "SELECT * FROM [prodlist] WHERE [product_name] = '" << variable << "';";
pRecordset = m_pConnection->Execute( query.str().c_str(), vRecordsAffected, 1 );
-
October 31st, 2003, 08:05 AM
#4
strcpy(ConStr, "SELECT * FROM prodlist WHERE product_name=");
strcat(ConStr, "'aegis 1.0'")
pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1);
strcpy(ConStr, "SELECT * FROM prodlist WHERE product_name=");
(ConStr, "'aegis 2.0'");//change Here ..
pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1);
OR
sprintf(ConStr, "SELECT * FROM prodlist WHERE product_name ='%s' ","aegis 2.0"); /// We can change Here ...
pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1);
Regards
Balamurali C
Last edited by ccbalamurali; October 31st, 2003 at 08:21 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|