在线程里操作数据库,当给执行下面操作时
adocommand.commandtext := SQLStr;
出错,如题。
各位赐教啦!

解决方案 »

  1.   

    拜托个位能不能用心点阿,不要折磨我了
    adocommand根本没有active 和 close ;有人知道ADOCommand.Parameters.ParseSql(STRSQL,True)这句怎么用吗?
      

  2.   

    不死鸟大哥,我的上下代码大概如下:
    FADORemoteCon.BeginTrans;
    try
      Off := FQueryLocal.FieldByName('OFFICE').AsString;
      Sty := FQueryLocal.FieldByName('STYLE').AsString;
      DBStr := 'insert into ' + Off + Sty
                                           +'(TIME,TRKGRP,CFG,MANTBUSY,TOTAL_USAGE,TOTAL_PC,OUT_USAGE,'
                                           +'IN_USAGE,OUT_PC,IN_PC,OUT_ANS_PC,OUT_ABAND_PC,IN_ANS_PC,'
                                           +'IN_ABAND_PC,ATB_USAGE,ATB_PC,OVERFLOWPC,SEIZ_FAIL_PC,MAX_USED,'
                                           +'MIN_USED,NOW_USED) '
                                           +'values(:TI,:TRK,:CFG,:MB,:TU,:TP,:OU,:IU,:OP,:IP,:OAP,:OABP,:IAP,:IABP,'
                                           +':AU,:AP,:OV,:SFP,:MAU,:MIU,:NU)';
               
    FADORemoteCommand.CommandText := DBStr;            FADORemoteCommand.Parameters.ParamByName('TI').Value := FQueryLocal.FieldByName('TIME').AsDateTime;
                FADORemoteCommand.Parameters.ParamByName('TRK').Value := FQueryLocal.FieldByName('TRKGRP').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('CFG').Value := FQueryLocal.FieldByName('P1').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('MB').Value := FQueryLocal.FieldByName('P2').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('TU').Value := FQueryLocal.FieldByName('P3').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('TP').Value := FQueryLocal.FieldByName('P4').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('OU').Value := FQueryLocal.FieldByName('P5').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('IU').Value := FQueryLocal.FieldByName('P6').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('OP').Value := FQueryLocal.FieldByName('P7').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('IP').Value := FQueryLocal.FieldByName('P8').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('OAP').Value := FQueryLocal.FieldByName('P9').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('OABP').Value := FQueryLocal.FieldByName('P10').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('IAP').Value := FQueryLocal.FieldByName('P11').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('IABP').Value := FQueryLocal.FieldByName('P12').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('AU').Value := FQueryLocal.FieldByName('P13').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('AP').Value := FQueryLocal.FieldByName('P14').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('OV').Value := FQueryLocal.FieldByName('P15').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('SFP').Value := FQueryLocal.FieldByName('P16').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('MAU').Value := FQueryLocal.FieldByName('P17').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('MIU').Value := FQueryLocal.FieldByName('P18').AsInteger;
                FADORemoteCommand.Parameters.ParamByName('NU').Value := FQueryLocal.FieldByName('P19').AsInteger;            FADORemoteCommand.Execute;
    Except   FADORemoteCon.RollbackTrans;
       DataSyncFail := True;
       FQueryLocal.Close;
       FADORemoteCon.Connected := false;
       FADOLocalCon.Connected := false;
       Exit;
    End;
      

  3.   

    Except 上少了一句 FADORemoteCon.CommitTrans;
      

  4.   

    adocommand.commandtext := SQLStr;
    应该不会出错,我刚试了一下你单步调试一下看看。另外,楼上指出的是
      

  5.   

    在FADORemoteCon.BeginTrans之前试加一句:
    FADORemoteCon.connection.open;
    先让它的连接激活
      

  6.   

    还有就是进了线程不知楼主是直接调用该过程?还是以command类的形式传参?
      

  7.   

    楼上兄弟,我的FADORemoteCon是在线程create时传进去的参数,
    FADORemoteCon在外边只是定义了,肯定没有其他的地方用到
    只在线程里才用到得,水连天兄弟 ,有办法吗〉?谢谢了
      

  8.   

    我贴出的代码是线程execute里的代码
    其中的FADORemoteCon是在线程create时通过参数传递进去的
    FADORemoteCon只在线程里用。其他的地方没有用过的