我用DELPHI作一数据库系统,在combobox中输入用户名时,操作一次后,再次输入时便提示“在此环境下不能执行此操作”,在baidu上搜竟然没有搜到相关帖子,请各位高手指点

解决方案 »

  1.   

    procedure TForm2.ComboBox1Exit(Sender: TObject);
    begin
    if combobox1.text<>'' then
      begin
          adodataset1.Close;
          adodataset1.CommandText:='select * from mima where 用户名=:username';
          adodataset1.Parameters.clear;
          adodataset1.Parameters.AddParameter;
          adodataset1.Parameters[0].Name:='username';
          adodataset1.Parameters[0].DataType:=ftstring;      adodataset1.Parameters[0].Direction:=pdinput;
          adodataset1.Parameters[0].Value:=combobox1.text;
          adodataset1.Active:=true;
        if adodataset1.Recordset.RecordCount=1 then
          begin
              if radiobutton1.Checked then
              begin
                  application.MessageBox('用户名重复,请重新输入!','提示信息',mb_ok);
                  combobox1.SetFocus;
              end
              else
              begin
                  RadioButton4.Checked:=adodataset1.fieldbyname('权限一').asboolean;
                  RadioButton5.Checked:=adodataset1.fieldbyname('权限二').asboolean;
              end;
          end
      else
        begin
            if not RadioButton1.Checked then
            begin
                  application.MessageBox('没有该用户名,请检查!','提示信息',mb_ok);
                  combobox1.SetFocus;
            end;
        end;
        adodataset1.close;
      end;
    end;
      

  2.   

    具体错误是:输入一个重复的用户名,然后提示重新输入,在输入时就出现这种情况。初学delphi,请多关照,谢谢了 
      

  3.   

    直接
    procedure TForm2.ComboBox1Exit(Sender: TObject); 
    begin 
    if combobox1.text < > ' ' then 
      begin 
          adodataset1.Close; 
          adodataset1.CommandText:= 'select * from mima where 用户名=:username '; 
          adodataset1.Parameters.clear; 
          self.ADODataSet1.Parameters.ParamByName('username').Value:=combobox1.text;
          adodataset1.open; 
        if ADODataSet1.RecordCount=1 then 
          begin 
              if radiobutton1.Checked then 
              begin 
                  application.MessageBox( '用户名重复,请重新输入! ', '提示信息 ',mb_ok); 
                  combobox1.SetFocus; 
              end 
              else 
              begin 
                  RadioButton4.Checked:=adodataset1.fieldbyname( '权限一 ').asboolean; 
                  RadioButton5.Checked:=adodataset1.fieldbyname( '权限二 ').asboolean; 
              end; 
          end 
      else 
        begin 
            if not RadioButton1.Checked then 
            begin 
                  application.MessageBox( '没有该用户名,请检查! ', '提示信息 ',mb_ok); 
                  combobox1.SetFocus; 
            end; 
        end; 
        adodataset1.close; 
      end; 
    end; 
      

  4.   

    没看清,还有问题,还有建议别用adodataset,用adoquery
    procedure TForm2.ComboBox1Exit(Sender: TObject);  
    begin  
    if combobox1.text  <  >  '  ' then  
      begin  
          adodataset1.Close;  
          adodataset1.CommandText:=  'select * from mima where 用户名=:username  ';  
          self.ADODataSet1.Parameters.ParamByName( 'username ').Value:=combobox1.text; 
          adodataset1.open;  
        if ADODataSet1.RecordCount=1 then  
          begin  
              if radiobutton1.Checked then  
              begin  
                  application.MessageBox(  '用户名重复,请重新输入!  ',  '提示信息  ',mb_ok);  
                  combobox1.SetFocus;  
              end  
              else  
              begin  
                  RadioButton4.Checked:=adodataset1.fieldbyname(  '权限一  ').asboolean;  
                  RadioButton5.Checked:=adodataset1.fieldbyname(  '权限二  ').asboolean;  
              end;  
          end  
      else  
        begin  
            if not RadioButton1.Checked then  
            begin  
                  application.MessageBox(  '没有该用户名,请检查!  ',  '提示信息  ',mb_ok);  
                  combobox1.SetFocus;  
            end;  
        end;  
        adodataset1.close;  
      end;  
    end;  
      

  5.   

    已解决,但不是代码的错误,谢谢hys_447兄弟