日期:2014-05-16  浏览次数:20462 次

关于delphi登陆窗体连接数据库的用法
 if Button1.Caption  =  '登陆(&L)  >' then
       begin
       ADOConnection1.Connected := true;

       ADOQuery1.Active := false;
       ADOQuery1.SQL.Clear;
       ADOQuery1.SQL.Add('select * from users');
       ADOQuery1.SQL.Add(' where userName = ' + quotedstr(trim(cb_username.Text)));
       ADOQuery1.SQL.Add(' and userpwd= ' + quotedstr(trim(ed_pwd.Text)));
       ADOQuery1.Active:= true;

       //ADOConnection1.Connected := false;
       //这句不能加,否则被断开连接了

       if not ADOQuery1.Eof  then
       begin
            Notebook1.PageIndex :=1;
            Button1.Enabled :=false;
         //这句不对的, RowsAffected是对“UPDATE”和“DELETE”操作有效的,对"SELECT"无效
         //if ADOQuery1.RowsAffected > 0 then
         //   begin
         //   Notebook1.PageIndex :=1;
         //   Button1.Enabled :=false;
         //   end
         // else
         //    begin
         //      showmessage('用户名或密码错误,请重新输入');
         //    end

        end
        else
            begin
               //showmessage('用户名或密码错误,请重新输入');
               Application.MessageBox('用户名或密码错误,请重新输入','提示',0)
            end
     end
     else
         begin
          Form1.Close;
         end;

?关于delphi登陆窗体连接数据库的用法

?