数据库表temp:  ID(primary key)   name    CID    ...............
               12365            A         00001
               67133            A         00002正常来说两条记录不会产生约束条件
但在delphi中出现这种情况(注:采用ODAC控件):
.................
 Orasession1.Connect;
 with OraQuery1 do
  begin
    close;
    SQL.Clear;
    SQL.Text:='select * from temp order by CID';
    open;
    First;
    IDNo:=24000
    while not Eof do
    begin      
      yhm:=fieldbyname('CID').AsString;
      with OraSQL1 do
      begin
        SQL.Clear;
        SQL.Text:='update temp set ID='+inttostr(strtoint(IDNO)+1)+' where CID='+yhm;
        execute;  -------------当更新ID=67133这条记录时候此处出现违反约束条件错误???
      end;
    end;
................搞了大半天搞不懂为什么会出现这个错误,
(1)用select * from temp where CID=00002 查看只有一条记录
(2)如果用SQL语句更新就可以。
不晓得么子原因
求助各位大侠高手,同时祝大家新年快乐,MONEY多多!!:)

解决方案 »

  1.   

    IDNo:=24000
    inttostr(strtoint(IDNO)+1)
    ------->
    这个是怎么回事?idno到底是什么类型?    while not Eof do
        begin      
          yhm:=fieldbyname('CID').AsString;
          with OraSQL1 do
          begin
            SQL.Clear;
            SQL.Text:='update temp set ID='+inttostr(strtoint(IDNO)+1)+' where CID='+yhm;
            execute;  -------------当更新ID=67133这条记录时候此处出现违反约束条件错误???
          end;
          next; //-------->你少了这个!!!!!!!
        end;
      

  2.   

    IDNO 是string 类型
    这只是伪码,
    程序专用有next;
    我忘记写上去了!
    sorry
      

  3.   

    我还发现如果代码改成这样就不会出错:
     Orasession1.Connect;
     with OraQuery1 do
      begin
        close;
        SQL.Clear;
        SQL.Text:='select ID,CID from temp order by CID';
        open;
        First;
        ....................
    就不会出错了!!!!!!!!
    SQL explorer中primary key中指定的主键或者唯一约束条件只有ID这一个
      

  4.   

    你的IDNO被插入重复值,不出现错误才怪
      

  5.   

    楼上的这位大哥,插入的怎么会是重复值呢?
    IDNO=24000是初始化参数,没有在循环里面
    循环里面的IDNO是递增的!!!
      

  6.   

    仔细检查数据库约束条件和odac设置,  顶!!!!