下面代码怎么改才能更简单些啊,比如用各种条件或循环语句什么的?procedure TForm1.Button1Click(Sender: TObject);
begin
adoquery1.sql.clear;
if combobox1.ItemIndex=0 then
begin
adoquery1.SQL.Add('select * from users where name='+quotedstr(edit1.Text));
end;
if combobox1.ItemIndex=1 then
begin
adoquery1.SQL.Add('select * from users where city='+quotedstr(edit1.Text));
end;
if combobox1.ItemIndex=2 then
begin
adoquery1.SQL.Add('select * from users where age='+quotedstr(edit1.Text));
end;
adoquery1.Open;end;
begin
adoquery1.sql.clear;
if combobox1.ItemIndex=0 then
begin
adoquery1.SQL.Add('select * from users where name='+quotedstr(edit1.Text));
end;
if combobox1.ItemIndex=1 then
begin
adoquery1.SQL.Add('select * from users where city='+quotedstr(edit1.Text));
end;
if combobox1.ItemIndex=2 then
begin
adoquery1.SQL.Add('select * from users where age='+quotedstr(edit1.Text));
end;
adoquery1.Open;end;
解决方案 »
- 如何知道 外部EDIT文本框是否获得输入焦点?
- edit1中比如有数字 '1234567 '如何让前三位(123)只读,后面的可以更改????
- 送分了!!!多线程程序中,为什么会出现线程乱串的问题.高手们解决!!!
- 有什么DELPHI控件可以支持DELPHI窗体在运行时设计呢?
- 求助,关于函数的参数?
- 如何让行高不是同样高,可自适应.
- 谁有INDY9.0,3ks
- 求《Delphi 7项目开发实践》内容简介的电子版
- DBGrid的实时刷新
- 请教一个用线程做一个动画的问题!
- idtcpserver如何主动向idtcpclient发送一条数据
- ocx控件中如何 读web服务器上文件(如:.doc),并将文件保存至本地???
strs:Array[0..2] of string;
begin
strs[0]:='name';
strs[1]:='city';
strs[2]:='age';
adoquery1.sql.clear;
adoquery1.sql.text:='select * from users where '+strs[combobox1.ItemIndex]+'='+quotedstr(edit1.Text));
.................
procedure TForm1.Button1Click(Sender: TObject);
var
sql : String;
begin case Combobox.Itemindex of
0: sql := ' where name='+quotedstr(edit1.Text);
1: sql := ' where city='+quotedstr(edit1.Text);
2: sql := ' where age='+quotedstr(edit1.Text);
end;
adoquery1.sql.clear;
adoQuery1.sql.text := 'select * from users '+sql;
adoquery1.Open;end;
procedure TForm1.Button1Click(Sender: TObject);
procedure InitCombobox;
begin
ComboBox1.Items.Add('name');
ComboBox1.Items.Add('city');
ComboBox1.Items.Add('age');
end;
var
sSql:string;
begin
InitCombobox;
sSql := 'select * from users where ' + ComboBox1.Text + ' = ' + QuotedStr(Edit1.Text);
adoquery1.Close;
adoquery1.SQL.Text := sSql;
adoquery1.Open;
end;