在delphi中更改一个SQL表中一字段值有哪些方法?下面为何编辑出错啊?
procedure TFmUser.Button1Click(Sender: TObject);
begin
  Update adoqbase set 'username'='123' ;
end;请帮手TKS!

解决方案 »

  1.   

    Query1.SQL.Clear;
    Query1.SQL.Add('update TABLENAME set column1 = 123 where column2 = 234');
    Query1.ExecSQL;
    将TABLENAME表中所有column2字段为234的记录的column1字段改为123。
      

  2.   

    function ExecuteSQL(Connection:TADOConnection;SQL: string): Boolean;
    var
      acTemp:TADOCommand;
    begin
      acTemp:=TADOCommand.Create(nil);
      try
        acTemp.CommandText:=SQL;
        try
          acTemp.Execute;
          Result:=True;
        except
          Result:=False;
        end;
      finally
        acTemp.Free;
      end;
    end;调用方法:
    procedure TForm1.DoUpdate;
    var
      SQL:string
    begin
      SQL:='UPDATE Customer SET CustomerID = 100 WHERE CustomerID=1';
      //前提是 Connection 这个对象已经存在,我想你用过 ADO 的话应该能明白。
      ExecuteSQL(Connection,SQL);
    end;
      

  3.   

    sorry 上面的例子忘了一句话,呵呵。我在给你补上。
    function ExecuteSQL(Connection:TADOConnection;SQL: string): Boolean;
    var
      acTemp:TADOCommand;
    begin
      acTemp:=TADOCommand.Create(nil);
      try
        acTemp.Connection:=Connection; //就是这句啦。sorry.
        acTemp.CommandText:=SQL;
        try
          acTemp.Execute;
          Result:=True;
        except
          Result:=False;
        end;
      finally
        acTemp.Free;
      end;
    end;调用方法:
    procedure TForm1.DoUpdate;
    var
      SQL:string
    begin
      SQL:='UPDATE Customer SET CustomerID = 100 WHERE CustomerID=1';
      //前提是 Connection 这个对象已经存在,我想你用过 ADO 的话应该能明白。
      ExecuteSQL(Connection,SQL);
    end;
      

  4.   

    多谢楼上各位!方法如下:
    1、TADOTable.FieldValues['字段名']=你的新值。
    2、修改adoquery的SQL为Update table set UserName='123456'
    3、加入一个adocommand控件,然后用commandtexe中加入Update table set UserName='123456'
    4、加入一个adostoreproc,使用SQL的存储过程请问是这样的吗?还有其它方法吗?