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我想用一个变量替代,我因该怎么写
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我想用一个变量替代,我因该怎么写
str :string;
begin
...
str :='update ry set qx1=''1'' where name=:aa';
...
dm.ry1.SQL.Add(str);
...
end;
可能可以用.請試試!
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;
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;
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;//是个变量