ETUser.DisableControls;
  try
  for i := 0 to wwDBGrid1.SelectedList.Count - 1 do
    begin
    ETUser.GotoBook(wwDBGrid1.SelectedList[i]);
  Userid.Text:=ETUser.FieldByName('Userid').AsString;
  pun:='';
  pun:=Trim(Userid.Text);
 s:='是否删除'+pun+'会员的所有资料';
 if messagedlg(s,mtconfirmation,[mbyes,mbno],0)=mryes then begin
   if DataSource1.DataSet.IsEmpty<>True then begin
   DataSource1.DataSet.Delete;
   end;
   //删除会员积分
 my.ETJifei.SQL.Clear;
 my.ETJifei.SQL.Add('delete Ujifei where Userid='''+pun+'''');
 my.ETJifei.UpdateBatch();
 end;
  finally
    ETUser.EnableControls;
  end;
积分表里有多条同一用户的数据,只能删除一条而且报错是哪问题?我应该怎么写

解决方案 »

  1.   

    my.ETJifei.close;
    my.ETJifei.SQL.Clear; 
    my.ETJifei.SQL.Add('delete from Ujifei where Userid='''+pun+''''); 
    my.ETJifei.ExecSQL;
      

  2.   

    UpdateBatch好像不是用在这里吧,执行delete语句要用ExecSQL,UpdateBatch是指你所修改的记录都在缓存里,然后一并提交,对于update,delete,insert等非选择性语句要用ExecSQL
      

  3.   

      ETUser.DisableControls; 
      try 
        for i := wwDBGrid1.SelectedList.Count - 1 downto 0  do 
        begin 
          ETUser.GotoBook(wwDBGrid1.SelectedList[i]); 
          Userid.Text:=ETUser.FieldByName('Userid').AsString; 
          pun:=''; 
          pun:=Trim(Userid.Text); 
        
          s:='是否删除'+pun+'会员的所有资料'; 
          if messagedlg(s,mtconfirmation,[mbyes,mbno],0)=mryes then 
          begin 
            if DataSource1.DataSet.IsEmpty <>True then begin 
            DataSource1.DataSet.Delete; 
          end; 
     
          //删除会员积分 
           my.ETJifei.SQL.Clear; 
          my.ETJifei.SQL.Add('delete Ujifei where Userid='''+pun+''''); 
          my.ETJifei.execsql
        end; 
      finally 
        ETUser.EnableControls; 
      end; 
      

  4.   

    刘德华同志也说了,要用ExecSQL,不用UpdateBatch