我用ACCESS数据库,做了一个BUTTON其代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
  i,j:integer;
  total:real;
begin
  ADOQuery1.Active:=false;
  ADOQuery1.Close;
  ADOQuery1.SQL.Text:='select 考号,yw,ywwc from cjb order by yw desc';
  ADOQuery1.Open;
  ADOQuery1.First;
  ADOQuery1.Active:=false;
  i:=1;
  j:=1;
  Total:=0.0;
  while not ADOQuery1.Eof do
  begin
    if Total<>ADOQuery1.FieldByName('yw').Asfloat then
      j:=i;
    ADOQuery1.Close;
    ADOQuery1.SQL.Text:='updata cjb set ywwc='+inttostr(j)+
    ' where 考号="'+ADOQuery1.FieldByName('考号').AsString+'"';
    ADOQuery1.ExecSQL;
    Total:=ADOQuery1.FieldByName('yw').Asfloat;
    i:=i+1;
    ADOQuery1.Next;
  end;
end;能运行,但始没有结果,即ywwc中没有内,哪位大侠能帮忙改一下,感激不尽!!!!!!!

解决方案 »

  1.   

    while   not   ADOQuery1.Eof   do 
        begin 
            if   Total <> ADOQuery1.FieldByName( 'yw ').Asfloat   then 
    这里不要用同一个数据集 
      

  2.   

    ADOQuery1.Active:=false; 
        ADOQuery1.Close; 
        ADOQuery1.SQL.Text:= 'select   考号,yw,ywwc   from   cjb   order   by   yw   desc '; 
        ADOQuery1.Open; 
        ADOQuery1.First; 
        ADOQuery1.Active:=false;  <=====你又把ADOQuery1关闭了!!!!
      

  3.   

    更改帖子的错误!!!
    ADOQuery1.SQL.Text:= 'updata   cjb   set   ywwc=……
    我写错了:
    ADOQuery1.SQL.Text:= 'update   cjb   set   ywwc=……
    并回复楼上:
    不关闭不行啊!运行出错!