我晕了!急急急急 :((10分)

S

studing

Unregistered / Unconfirmed
GUEST, unregistred user!
var s:string;
begin
if combobox1.text<>'' then s:='combobox1.text:="'edit1.text'"';
with table1 do
begin
query1.close;
query1.sql.text:='select * from ryxi.db where '+s;
query1.open;
end;
end;
end.
在combobox1.text和edit1.text中输入条件,执行后出现非法的关键字,程序那一点出错了!
希望能指出!单步执行后在query1.open处提示出错,不知错在那里了!急!!!!



 
看不明白你的附值语句
 
把...改为:
if combobox1.text<>'' then s:=combobox1.text + '=' + edit1.text;

试试看:
 
var s:string;
begin
if combobox1.text<>'' then s:=combobox1.text+'='''+edit1.text+'''';
with table1 do
begin
query1.close;
query1.sql.text:='select * from ryxi.db where '+s;
query1.open;
end;
end;
end.
全是单引
 
我的意思是,在combobox1.text中选择要查询的字段,在edit1.text中输入该字段的记录,比如
编号=001,
 
>>s:='combobox1.text:="'edit1.text'"';
这句是什么乱七八糟的?
>> query1.sql.text:='select * from ryxi.db where '+s;

Where 后面没有写对。
 
用我前面所说的(s:=combobox1.text + '=' + edit1.text)不能解决吗?
 
to jobsxy:用你的方法还是不行,错误提示依旧!
还有没有解决的办法!请大家能够给出答案,分数不够可以在加!
 
有两个办法可以解决。
第一,采用动态的参数,可以看看李维先生的书。
第二,如下:
请你采用TQuery控件。
var s, strsql: string;
begin
if (combobox1.text <> '') and (edit.text <> '') then
begin
s := edit.text;
strsql := 'select * from ryxi.db where ' + combobox.text + ' = ' + QuotedStr(s);
query1.close;
query1.sql.clear;
query1.sql.add(strsql);
query1.open;
end;
end;


 
query1.sql.text:='select * from ryxi.db where '+s;
s:='combobox1.text:="'edit1.text'"';
这两句什么意思? 看不懂呀
你的SQL整理后就是:
select * from ryxi.db where combobox1.text:="'edit1.text'" ?????!!!!!!!!
这个也行呀?
改成:SQL.Clear;
SQL.add('select * from ryxi.db where 字段名='+ ComboBox.text);
SQL.add(' and 字段名='+ Edit1.text)
 
我的意思是,在combobox1.text中选择要查询的字段,在edit1.text中输入该字段的记录,比如
编号=001,
用上面的方法还是同样的错误提示!用单步执行时,运行到query1.open 出错!真的很急!
希望大虾门能给出解决的办法!
 
var s:string;
begin
if combobox1.text<>'' then
s := combobox1.text + '=' + '''' + edit1.text + '''';
with table1 do
begin
query1.close;
query1.sql.text:='select * from ryxi.db where '+s;
query1.open;
end;
肯定对,一定给分哟
 
是要单引号是双引号呀?
if combobox1.text<>'' then
s := combobox1.text + '=''' + edit1.text +'''';
或者
if combobox1.text<>'' then
s := combobox1.text + '="' + edit1.text +'"';
 
你用我上面的应该不会有错啊
你可以QUERY.SQL.SAVETOFILE('TEMP.TXT')看看到底是对还是错
 
不知道你的ComboBox1选择的字段的数据类型是什么?
如果number
则如下:
s:=ComboBox1.Text+'='+Edit1.Text;
如果varchar or char
s:=ComboBox1.Text+'='''+Edit1.Text+'''';
如果是date(oracle)
s:=ComboBox1.Text+'='''+Format('yyyy-MM-dd',Edit1.Text)+'''';
 
换个方法吧,用动态参数
query1.Close;
query1.SQL.Clear; yskrq>=:SDate And yskrq<=:EDate
query1.SQL.Add('select * from ryxi.db where '''+ComboBox.text+'''=:EDate');
query1.Parameters.ParamByName('EDate').Value:=edit1.text;
try
query1.Open;
except
Query1.ExecSQL;
end;
 
问题不是很复杂,要根据字段类型做相应的格式调整!
 
问题搞定,多谢各位的帮忙!分分了!
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
518
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部