dm.ry1.Close;
dm.ry1.SQL.Clear;
dm.ry1.SQL.Add('update ry set qx1=''1'' where name=:aa');
dm.ry1.ParamByName('aa').AsString:= xx ;
dm.ry1.ExecSQL;
这里的qx1我想用一个变量替代,我因该怎么写

解决方案 »

  1.   

    設個字符串變量就了吧.
    str :string;
    begin
    ...
    str :='update ry set qx1=''1'' where name=:aa';
    ...
    dm.ry1.SQL.Add(str);
    ...
    end;
    可能可以用.請試試!
      

  2.   

    不是了老大,是sql语言里的qx1我想用变量代替
      

  3.   

    这样也可以:
    var
      sFieldName:string;
    begin
      dm.ry1.Close;
      dm.ry1.SQL.Clear;
      sFieldName := 'qxl';
      dm.ry1.SQL.Add('update ry set '+sFieldName+'=''1'' where name=:aa');
      dm.ry1.ParamByName('aa').AsString:= xx ;
      dm.ry1.ExecSQL;
    end;
      

  4.   

    var 
      TheStrOfField : String ;TheStrOfField := qx1 ;
    With TADOQuery.Create(nil) do
      begin
        Try 
          Begin
            Connection := ADOConnection1 ;
            //ConnectionString := '...' ;
            Sql.Text := 'Update ry Set ''TheStrOfField'' = ''1'' where Name =: aa ' ;
            ExecSql ;
          end;
        Finally
          Free ;
        End; 
      end;
      

  5.   

    错了应该是:var 
      TheStrOfField : String ;TheStrOfField := qx1 ;
    With TADOQuery.Create(nil) do
      begin
        Try 
          Begin
            Connection := ADOConnection1 ;
            //ConnectionString := '...' ;
            Sql.Text := 'Update ry Set' + TheStrOfField + '= ''1'' where Name =: aa ' ;
            ExecSql ;
          end;
        Finally
          Free ;
        End; 
      end;//是个变量