根据VC编辑框的输入,把输入的字符串组合成一句sql语句

[复制链接]
查看11 | 回复2 | 2010-9-20 22:30:03 | 显示全部楼层 |阅读模式
如题,where后的所有东西都是根据输入来决定,例如where a=b;其中a,=,b都是根据输入决定的,连等于号都是,请问这个sql语句如何实现,要使用Format格式化这个语句。
给出点提示:
int pos;
int pos1;
CString sql;
CString neirong;//第一个组合框内容
CString fangshi;//第二个组合框内容
CString chanxu;//编辑框内容
//_variant_t jiluji;//查到的结果
pos=m_tiaojian.GetCurSel();

m_tiaojian.GetLBText(pos, neirong);
pos1=m_fangshi.GetCurSel();
m_fangshi.GetLBText(pos1,fangshi);
m_chaxunneirong.GetWindowText(chanxu);
//chanxu=_T("#")+chanxu+_T("#");
ADO m_ADO;
m_ADO.OnInitADO();

sql.Format(_T("select * from tabypinfo where '+%s+' +%s+ '+%s+'"),neirong,fangshi,chanxu);
但是sql语句是错误的,如何改正过来?

回复

使用道具 举报

千问 | 2010-9-20 22:30:03 | 显示全部楼层
sql.Format(_T("select * from tabypinfo where '+%s+' +%s+ '+%s+'"),neirong,fangshi,chanxu);改为:sql.Format(_T("select * from tabypinfo where \'%s\' %s \' %s\'"),neirong,fangshi,chanxu);试试,应该可以的
回复

使用道具 举报

千问 | 2010-9-20 22:30:03 | 显示全部楼层
sql.Format(_T("select * form tabypinfo where%s%s%s"),neirong,fangshi,chanxu);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行