with datamodule6.ADOQuery3 do
    begin
      if active then
        close;
      SQL.Clear;
      SQL.add('select * from 用户');
      ExecSQL;
      open;
      if RecordCount>0  then
        begin
          first;
          if Locate('帐号,用户级别',vararrayof([strUser,未审核']),[locaseinsensitive]) then
            begin
              if application.messagebox(确定通过?', '提示',mb_YesNo+MB_APPLMODAL+MB_ICONQUESTION+MB_DEFBUTTON2)=idyes then
                begin
                  edit;
                  fieldByName('用户级别').AsString:='user';
                  post;
                end
              else
                exit;
            end;
         end;
      DataModule6.ADOQuery3.Refresh;
    end;
  此条记录数据库里面已经存在,我只是修改,但出错,什么原因?
 错误提示:由于在主关键字,索引值,主键中存在重复的记录,不能保存!!

解决方案 »

  1.   

    SQL.Clear;
          SQL.add('select * from 用户');
          ExecSQL;
          open;
    >>>>
    ExecSQL;是没有用的open 就可以了
      

  2.   

    begin
    ////////////////////////////////////////
                      open;
    ///////////////////////////////////
                      edit;
                      fieldByName('用户级别').AsString:='user';
                      post;
                    end
      

  3.   

    if RecordCount>0  then
            begin
              first;????????????????   next 呢?
              if Locate('帐号,用户级别',vararrayof([strUser,未审核']),[locaseinsensitive]) then
                begin
                  if application.messagebox(确定通过?', '提示',mb_YesNo+MB_APPLMODAL+MB_ICONQUESTION+MB_DEFBUTTON2)=idyes then
                    begin
                      edit;
                      fieldByName('用户级别').AsString:='user';
      

  4.   

    with datamodule6.ADOQuery3 do
        begin
          if RecordCount>0  then
            begin
              first;
              if Locate('帐号;用户级别',vararrayof([strUser,'未审核']),[locaseinsensitive]) then
                begin
                  while not eof do
                    begin
                      if fieldByName('帐号').AsString=strUser then
                        begin
                          if application.messagebox('确定拒绝此用户?', '提示',mb_YesNo+MB_APPLMODAL+MB_ICONQUESTION+MB_DEFBUTTON2)=idyes then
                            delete
                          else
                            exit;
                        end;
                      next;
                    end;
                end;
             end;
          CleaNilEdit;
          DataModule6.ADOQuery3.Refresh;
        end;
    我这样好像就可以了
      

  5.   

    fieldByName('用户级别').AsString:='user';
    这么写不对,fieldByName().AsString只能给变量附值,如果修改数据库字段的值,要用
    SQL语句的Update语句,例如:
    update 表名 set 字段名=  where 限制条件= ;
      

  6.   

    将这句去掉DataModule6.ADOQuery3.Refresh;
      

  7.   

    我修改后倒是正确了,但实现方式不好,回来我一定试试,到底是什么原因?
    to: saien(有问必答) 
    这一句不出错,我要看到修改后的记录,所以肯定是要要的!是执行post;时候出错!
      

  8.   

    修改好的如下:
      with datamodule6.ADOQuery3 do
        begin
          if RecordCount>0  then
            begin
              first;
              if Locate('帐号,用户级别',vararrayof([strUser,'未审核']),[locaseinsensitive]) then
                begin
                  while not eof do
                    begin
                      if fieldByName('帐号').AsString=strUser then
                        begin
                          if application.messagebox('确定通过?, '提示',mb_YesNo+MB_APPLMODAL+MB_ICONQUESTION+MB_DEFBUTTON2)=idyes then
                            begin
                              edit;
                              fieldByName('用户级别').AsString:='user';
                              post;
                            end
                          else
                            exit;
                        end;
                      next;
                    end;
                end;
             end;
          CleaNilEdit;
          DataModule6.ADOQuery3.Refresh;
        end;
    这样不好,大家帮我改改,谢谢!
      

  9.   

    to:hmzgz81  为什么不用post?