query1.sql.add('insert into hotle_charge(room,login_time,charge,flow_up,flow_down,used_time) values (account,record_time,cost,up_bytes,down_bytes,duration) ');
错误提示是:不允许使用account。此处只允许使用常量、表达试或变量!但是account是我自己定义的变量啊,请问要怎么改?代码:
procedure TForm1.Button1Click(Sender: TObject);
var
  account     : String;
  record_time : String;
  cost        : double;
  up_bytes    : integer;
  down_bytes  : integer;
  duration    : integer;
begin
while not table1.eof do
begin
  if query1.active then query1.Active := false;
  account       :=table1.fieldbyname('FM_ACCOUNT').asstring;//or asint ,asfloot...
  record_time   :=table1.fieldbyname('FM_RECORD_TIME').asstring;
  cost          :=table1.fieldbyname('FM_COST').Asfloat;
  up_bytes      :=table1.fieldbyname('FM_UP_BYTES').asinteger;
  down_bytes    :=table1.fieldbyname('FM_DOWN_BYTES').asinteger;
  duration      :=table1.fieldbyname('FM_DURATION').asinteger;
  query1.SQl.Clear ;
  query1.sql.add('insert into hotle_charge(room,login_time,charge,flow_up,flow_down,used_time) values (account,record_time,cost,up_bytes,down_bytes,duration) ');
  query1.ExecSQL;
  table1.Next;
end;

解决方案 »

  1.   

    靠!你都写成字符串提交到数据库里了,数据库怎么认得你的account, record_time, ....是什么东西啊。记住:数据库要的是数据!
    方法我不教你,你自己看书,对你有好处。
      

  2.   

    代码:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      account     : String;
      record_time : String;
      cost        : double;
      up_bytes    : integer;
      down_bytes  : integer;
      duration    : integer;
    begin
    while not table1.eof do
    begin
      if query1.active then query1.Active := false;
      account       :=table1.fieldbyname('FM_ACCOUNT').asstring;//or asint ,asfloot...
      record_time   :=table1.fieldbyname('FM_RECORD_TIME').asstring;
      cost          :=table1.fieldbyname('FM_COST').Asfloat;
      up_bytes      :=table1.fieldbyname('FM_UP_BYTES').asinteger;
      down_bytes    :=table1.fieldbyname('FM_DOWN_BYTES').asinteger;
      duration      :=table1.fieldbyname('FM_DURATION').asinteger;
      query1.SQl.Clear ;
      query1.sql.add('insert into hotle_charge(room,login_time,charge,flow_up,flow_down,used_time) values (:account,:record_time,:cost,:up_bytes,:down_bytes,:duration) ');  query1.ParamByName('account').Asstring := account;
      //其余的类似这样写 
      query1.ExecSQL;
      table1.Next;
    end;
      

  3.   

    出现一个错误,hotle_charge对象名无效,这是我的SQL SERVER 的表名,请问要怎么改啊?