导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
2003/5/10 12:16:51
标题:
加入我的收藏
楼主:
请看小弟的一段程序: 我想表达的查询语句是: select shi from shengshi where sheng='河南' group by shi 现在我想将查询条件设置为一个变化的值,如放置在combobox中: mysql:='select shi from shengshi where sheng='+combobox1.text+' group by shi'; adoquery.sql.add(mysql); 总是报错 ,我想可能是那个单引号的问题,因为在正常的SQL语句中WHERE XX='YY'需要一个单引号,但象我那样的化就相当于没有引号了,变成了: select shi from shengshi where sheng=河南 group by shi 请问怎样解决这个问题??
----------------------------------------------
新手,想得到您的帮助!
作者:
2003/5/10 12:44:16
1楼:
adoquery.close; with adoquery.sql do begin clear; add('select shi from shengshi') add('where sheng=:hl'); add('group by shi'); end; adoquery1.Parameters.ParamByName('hl').Value :='河南'; query.open;
----------------------------------------------
我是小菜鸟,我怕谁
作者:
2003/5/10 14:12:45
2楼:
如下也可: sSql := Format('Select she from shengshi Where sheng = %s group by shi',[Trim(Edt.Text)] ; with AdoQuery do begin if Active then Close ; with Sql do begin clear ; Add(sSql) ; end ; Prepared ; Open ; end ; //OK!
----------------------------------------------
作者:
cjrb (Thinking In 魂)
★☆☆☆☆
-
盒子活跃会员
2003/5/10 14:18:22
3楼:
mysql:='select shi from shengshi where sheng='+''+combobox1.text+''+' group by shi';
----------------------------------------------
充电..........
作者:
2003/5/10 14:26:55
4楼:
''中第一个与第四个是限界符,第二个起转义符作用,类似C中的/
----------------------------------------------
链接:https://pan.baidu.com/s/12jzmECYKhGCsHBxz8tmB6w 提取码:pelr --来自百度网盘超级会员V9的分享
作者:
2003/5/10 17:23:49
5楼:
又学到了点东西,我试一下,谢谢楼上各位!!
----------------------------------------------
新手,想得到您的帮助!