-
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??
-
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 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 );
-
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