select * from xxxx where 'combobox1.text'='edit1.text'有错吗!~xxxx是个SQL表(50分)

  • 主题发起人 主题发起人 SomeBody
  • 开始时间 开始时间
S

SomeBody

Unregistered / Unconfirmed
GUEST, unregistred user!
出错的问题好象是在说我的combobox1.text 和 edit1.text不是一个有效的TABLE!在WHERE后面是不是
不能用这些控件表示啊!不能的话怎么办啊!
 
使用参数吧.
query1.sql='select * from xxxx where :a1=:a2';
query1.param[0].AsString:=combobox1.Text;
query2.param[1].AsString=edit1.text;
ok?
 
'select * from xxxx where '+''combobox1.text''+'='+''''+edit1.text+''''
整个字串
 
'select * from xxxx where '+ combobox1.text + ' = ''' + edit1.text + ''''
 
请参阅以下动态查询
const hz='select cxfl,khmc,sum(yes),sum(yef) from %s where cxfl="%s" group by cxfl,khmc';
query1.sql.close;
query1.sql.clear;
query1.SQL.Add(format(hz,['rmbmx',combobox2.items[combobox2.itemindex]]));
query1.sql.open;
 
agree RedBeret
 
用参数,看上去也清楚点
 
你的combobox1.text中存放的必须是有效的字段名, 如下SQL 可以执行:
query1.sql.close;
query1.sql.clear;
query1.sql.add('select * from xxxx where ')
query1.sql.add( combobox1.text + ' = ' +''''+ edit1.text + '''');
query1.sql.open;
即在SQL 里面不能有Delphi的控件内容, 必须是字段名和常量。

 
agree RedBeret.但要注意edit1.text中不要有单引号或双引号。
 
var
sqlstr:String;
procedure ........
begin
sqlstr := 'select * from xxxx where ' + combobox1.text + '=' + edit1.text
Query1.Sql.Text := sqlstr;
Query1.Open;
end;

简单明了。。

 
用参数加paramsbyname
 
'select * from xxxx where '+combobox1.text+'='+'''edit1.text''''
加引号就对了
 
''''为单引号
Query.sql.add('select * from xxxx where '+combobox1.text+'='+''''+edit1.text+'''');
Query.sql.open;
 
我等会试试看看啊!不知道能不能用,不过我看你们写的引号的用法都不是一样有没有人用错了 啊!
还是多谢你们哦/1这么快就来了/1明天分分哦/1
 
query1.sql.add('selecet * from xxxx where combobox1.text='''+edit1.text+'''');
 

SQL.Add(select * from xxxx where :a='''edit1.text'''');
parambyname(a).asstring:=combobox1;

ok!
 
//用参数
with Query1 do
begin
Close;
Sql.Clear;
Sql.Add('select * from xxxx where :p1 = :p2');
ParamByName('p1').asstring := Trim(combobox1.text);
ParamByName('p2').asstring := Trim(edit1.text);
Open;
end;
 
redbegret的前中!不过还是谢谢各位啊!
 
可用select * from xxxx where+#39+combobox1.text+#39+'='+#39+edit1.text+#39
这样就可以用了.如用参数表示直观. 我常有参数表示
 
后退
顶部