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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ExecuteSQL( ) and CStrings

Status
Not open for further replies.

ewan91

Programmer
Jun 25, 2001
13
GB
hello i'm trying to update mt datacase with the following function

void CResultSet::Update2001(CString lab, CString con, CString lib, CString oth, CString seat )
{
m_hdbc.OpenEx("DSN=EwanProject");

CString update = "UPDATE 2001VOTE " +
CString ("SET LABOUR = ");
update += lab +
CString (", CONSERVATIVE = ");
update += con +
CString (", LIBDEM = ");
update += lib +
CString (", OTHER = ");
update += oth +
CString (" WHERE SEAT LIKE ");
update += seat;

m_hdbc.ExecuteSQL( update );

m_hdbc.Close( );
}

but i get the error, too few parameters, 1 expected. if i comment out
//update+=seat; and write in the name of the seat eg
CString (" WHERE SEAT LIKE 'ABERVAN'");
the code works but i need to be able to change the name of the seat

any ideas what is going wrong

thanks
ewan
 
- cast your CString to (LPCSTR) before passing it as an argument;
- don't use names for strings that resembles some SQl commands
- also check your column names for mispell errors. s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Perhaps a more "elegant" way to do it would be :-

void CResultSet::Update2001(CString lab, CString con, CString lib, CString oth, CString seat )
{
m_hdbc.OpenEx("DSN=EwanProject");

CString update;

update.Format("UPDATE 2001VOTE SET LABOUR=%s,
CONSERVATE=%s,
LIBDEM=%s,
OTHER=%s WHERE SEAT LIKE '%s'",
lab, con, lib, oth, seat);

m_hdbc.ExecuteSQL(update);

}

Note: the update.Format line is all one line

You have more control over the string using the standard 'printf' formatting strings (%s,%i,%lf, etc..)

I like it anyway !!!!! Spencer Window (not a joke name)
spencer.window@eastmidlandcomputers.ltd.uk
 
After typing all the above, I've just noticed what's wrong with you original code !!!

You are not putting the contents of seat inside single quotes. Change last part of code to read :-

CString (" WHERE SEAT LIKE '");
update += seat + "'";

Still prefer using .Format function of CString.....
Spencer Window (not a joke name)
spencer.window@eastmidlandcomputers.ltd.uk
 
i got it to work using your second version

i agree the first is better and may try that later

thanks

ewan
 
what does it mean?

CString update = "UPDATE 2001VOTE " +
CString ("SET LABOUR = ");

I think you need

CString update = CString("UPDATE 2001VOTE ") +
CString ("SET LABOUR = ");
John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top