我要根据A表中的字段,BIN,去更新,WHDATA表中对应字段CLASS的数据?
我用了二个查询对象,先是从BinRankBlace中找出所有BIN,和对应的CLASS,难后再去找更新WHDATA数据中BIN对应的CLASS数据!老是失败,
我的源码如下,
procedure Tfrmupdateclass.updateclass1 ;
var
count:Integer;
a:string;
b:string;
begin
qryupdate1.Close;
qryupdate1.SQL.Clear;
qryupdate1.SQL.Add('select BIN,class from [BinRankBlace]');
qryupdate1.Open;if qryupdate1.eof then
begin
  Application.MessageBox(PChar('查无数据!'), PChar('温馨提示'), MB_OK +
    MB_ICONINFORMATION);
  Exit;
end;
  count:=0;
 while not qryupdate1.eof do
 begin
   //更新数据
   count:=count+1;
   qryupdate2.Close;
   qryupdate2.SQL.Clear;
   qryupdate2.SQL.Add('update [whdata] set class=:a where BinNo=:b and class=:c');
   qryupdate2.Parameters.ParamByName('a').Value :=qryupdate1.FieldByName('class').AsString;;
   qryupdate2.Parameters.ParamByName('b'). value:=qryupdate1.FieldByName('BIN').AsString;
   qryupdate2.Parameters .ParamByName('c').Value :=null;
   qryupdate2.ExecSQL;
   qryupdate2.Close;
   qryupdate1.Next; end;
 Application.MessageBox(PChar(count), PChar('温馨提示'), MB_OK +
  MB_ICONINFORMATION);end;

解决方案 »

  1.   

    procedure Tfrmupdateclass.updateclass1 ; 
    var 
    count:Integer; 
    a:string; 
    b:string; 
    begin 
    qryupdate1.Close; 
    qryupdate1.SQL.Clear; 
    qryupdate1.SQL.Add('select BIN,class from [BinRankBlace]'); 
    qryupdate1.Open; if qryupdate1.IsEmpty then 
    begin 
      Application.MessageBox(PChar('查无数据!'), PChar('温馨提示'), MB_OK + 
        MB_ICONINFORMATION); 
      Exit; 
    end; 
      count:=0; 
    qryupdate1.First;
    while not qryupdate1.eof do 
    begin 
      //更新数据 
      count:=count+1; 
      qryupdate2.Close; 
      qryupdate2.SQL.Clear; 
      qryupdate2.SQL.Add('update [whdata] set class=:a where BinNo=:b and class=:c'); 
      qryupdate2.Parameters.ParamByName('a').Value :=qryupdate1.FieldByName('class').AsString;; 
      qryupdate2.Parameters.ParamByName('b'). value:=qryupdate1.FieldByName('BIN').AsString; 
      qryupdate2.Parameters .ParamByName('c').Value :=null; 
      qryupdate2.ExecSQL; 
      qryupdate2.Close; 
      qryupdate1.Next; end; 
    Application.MessageBox(PChar(count), PChar('温馨提示'), MB_OK + 
      MB_ICONINFORMATION); end;
      

  2.   


    procedure Tfrmupdateclass.updateclass1 ; 
    var 
    count:Integer; 
    a:string; 
    b:string; 
    begin 
    qryupdate1.Close; 
    qryupdate1.SQL.Clear; 
    qryupdate1.SQL.Add('select BIN,class from [BinRankBlace]'); 
    qryupdate1.Open; if qryupdate1.IsEmpty then 
    begin 
      Application.MessageBox(PChar('查无数据!'), PChar('温馨提示'), MB_OK + 
        MB_ICONINFORMATION); 
      Exit; 
    end; 
      count:=0; 
    qryupdate1.First; 
    while not qryupdate1.eof do 
    begin 
      //更新数据 
      count:=count+1; 
      qryupdate2.Close; 
      qryupdate2.SQL.Clear; 
      qryupdate2.SQL.Add('update [whdata] set class=:a where BinNo=:b and class=:c'); 
      qryupdate2.Parameters.ParamByName('a').Value :=qryupdate1.FieldByName('class').AsString;; 
      qryupdate2.Parameters.ParamByName('b'). value:=qryupdate1.FieldByName('BIN').AsString; 
      qryupdate2.Parameters .ParamByName('c').Value :=null; 
      qryupdate2.ExecSQL; 
      qryupdate2.Close; 
      qryupdate1.Next; end; 
    Application.MessageBox(PChar(count), PChar('温馨提示'), MB_OK + 
      MB_ICONINFORMATION); end;
      

  3.   

    SQLServer?多表更新:
    update A set
      a.class = b.class
    from [BinRankBlace] A, [whdata] B
    where a.Bin = b.BinNO and a.class = b.class其它数据库未试过。
      

  4.   

    用的是ACCESS,试过了cmdream的,不行,对话框不显示变量记录数,数据未更新!郁闷,到底是哪里错了?