procedure TForm1.FormCreate(Sender: TObject);
begin
  query.SQL.Clear;
        query.SQL.Add('select username from renyuanbiao'); // 从用户表中查询出来
       query.Open;
       if query.RecordCount > 0 then
       begin
               query.First;
            while not query.Eof do
            begin
              ComboBox1.Items.Add(query.fieldbyname('username').AsString);
                query.Next;
             end;
        end;
        //query.Free;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
 query.SQL.clear;
  query.SQL.add('select password from renyuanbiao where  username='''+ComboBox1.Text+'''' );
  query.open;
if query.FieldByName('password').AsString =trim(edit1.Text)
then
  showmessage('登录成功')  ;
end;
有什么错误啊

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject); 
    begin 
    query.close;
     query.SQL.clear; 
      query.SQL.add('select password from renyuanbiao where  username='''+ComboBox1.Text+'''' ); 
      query.open; 
    if query.FieldByName('password').AsString =trim(edit1.Text) 
    then 
      showmessage('登录成功')  ; 
    end; 
      

  2.   

    query.close;//缺少这一句,但是程序没有问题可以运行。
    procedure TForm1.Button1Click(Sender: TObject);  
    begin  
    query.close;//缺少这一句,但是程序可以运行。 
     query.SQL.clear;  
      query.SQL.add('select password from renyuanbiao where  username='''+ComboBox1.Text+'''' );  
      query.open;  
    if query.FieldByName('password').AsString =trim(edit1.Text)  
    then  
      showmessage('登录成功')  ;  
    end;
      

  3.   

    在query.open;之前加个:query.sql.savetofile('E:\\a.txt');看下SQL语句是否正确。