Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assistance Needed Using a SQL Where Clause 1

Status
Not open for further replies.

brendasql

Programmer
Apr 1, 2003
58
US
Hi All -

New to C++ and I am having problems with the syntax. I have been able to make a ADODB connection string to work and I can do a "Select Field from Table" to return the results. Please note that at the moment I only have one record in the table so it only returns this one record, however I need to add the "Where" clause to my select statement so that I can retrieve only the specific record when the table and application go into production. So far everything that I have tried has not worked, either it will not compile or it compiles but will not return any results.

Here's my code.....please help

char chrHostID[10]; /****this is the field that contains the value for the WHERE Clause***/

RecSet = pConn->Execute("Select Roles from Employees", RecordsAffected, 1);

pField = RecSet->Fields->GetItem("Roles");

vField.Clear();
vField=pField->Value;
WideCharToMultiByte(CP_ACP, 0, vField.bstrVal, -1, sField, 100, NULL, NULL);



Thanks in advance for any help provided!!![bigsmile]
 
You did not specify the column names you want to search

Say the possible values for Roles are boss, bosspa, woker. If you want the role specified in the string role
Code:
#include <sstream>
#include <string>
...
std::string role = "worker";
...
std::ostringstream query;
query << "select Roles from Employees where Roles like '" << role << "'";
std::string querystr = query.str();
std::cout << querystr << std::endl;
RecSet = pConn->Execute(querystr.c_str(), RecordsAffected, 1);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top