procedure TForm2.Button1Click(Sender: TObject);
begin
if xx.ItemIndex =0 then
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ;
query1.open ;
if xx.ItemIndex=1 then
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ;
query1.open ;
end;
begin
if xx.ItemIndex =0 then
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ;
query1.open ;
if xx.ItemIndex=1 then
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ;
query1.open ;
end;
前面最好加上一句:
query1.Close;
begin
case xx.ItemIndex of
0:begin
with Query1 do
begin
SQL.Clear;
SQL.Add('SELECT * FROM RenYuanBiao WHERE UserName='''+Edit1.Text+'''');
open;
end;
end;
1:begin
with Query1 do
begin
SQL.Clear;
SQL.Add('SELECT * FROM RenYuanBiao WHERE Name='''+Edit1.Text+'''');
open;
end;
end;
end;
是不是通不过啊?query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ;
query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ;
改成这样
query1.SQL.Add('select * from renyuanbiao where username='+''''+edit1.Text+'''') ;
query1.SQL.Add('select * from renyuanbiao where name='+''''+edit1.Text+'''') ; 注意代码写的规范些,区分大小写,修改起来会方便
[Error] Unit2.pas(70): Declaration expected but end of file found
[Fatal Error] cwxt.dpr(15): Could not compile used unit 'Unit2.pas'
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
if xx.ItemIndex =0 then
begin
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ;
query1.open ;
end;
if xx.ItemIndex=1 then
begin
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ;
query1.open ;
end;
end;
为什么还要加个end啊
begin
if xx.ItemIndex =0 then
begin
query1.close;
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ;
query1.open;
end;
if xx.ItemIndex=1 then
begin
query1.close;
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ;
query1.open;
end;
end;
begin
IF Active Then Close;//记得要关闭活动连接
SQL.Clear;
SQL.Add('SELECT * FROM RenYuanBiao WHERE Name='''+Edit1.Text+'''');
open;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
if xx.ItemIndex =0 then
begin
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' );
query1.open;
end;
if xx.ItemIndex=1 then
begin
query1.SQL.Clear ;
query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' );
query1.open;
end;
end;
最后加end;
希望楼主写代码时养成一个良好的编程风格,包括缩进,命名等等,对你自己排错或看代码也容易很多!
begin
query1.Close;
query1.SQL.Clear ;
if xx.ItemIndex =0 then
query1.SQL.Add('select * from renyuanbiao where username='''+edit1.Text+'''' ) ;
else if xx.ItemIndex=1 then
query1.SQL.Add('select * from renyuanbiao where name='''+edit1.Text+'''' ) ; query1.open ;
end;
procedure LoadUser;
begin
With Query1 do
begin
Close;
Sql.Clear;
Sql.Text:='select * from renyuanbiao';
Open;
end;
end;
begin
LoadUser;
Case xx.ItemIndex of
0:Query1.Filter:='Username='+QuotedStr(edit1.Text);//用Filter即可
1:
end;
end;