我通过savetofile函数将数据库中的数据备份为xml格式,再将xml文件导入到数据库中,通过clientdataset3.LoadFromFile(xml文件的地址)将数据存入clientdataset3中,再将其一条一条的写入clientdataset2中,测试第一次运行时正常,但第二次运行同样的时,会出现clientdataset中再无法识别新的SQL了,只能识别第一次中的SQL,也就是向原来的SQL存入缓存中没有被清空一样,具体代码如下:     if trim(edit10.Text)='' then  //edit10.Text中为xml文件的路径
        begin
          showmessage('请选择数据源!');
          edit10.SetFocus;
          exit;
        end;
  //将xml文件名拆开,第一位记录如为B则为火灾报告表,如为P则为执勤表,再后八位为单位编码,再就是四位年加两位月-两位月
      filename:=copy(trim(edit10.Text),length(trim(edit10.Text))-21,1); //第一位得出是B还是P 
      dwbm:=copy(trim(edit10.Text),length(trim(edit10.Text))-20,8); //单位编码
      year:=copy(trim(edit10.Text),length(trim(edit10.Text))-12,4); //年
      month1:=inttostr(strtoint(copy(trim(edit10.Text),length(trim(edit10.Text))-8,2)));//月
      month2:=inttostr(strtoint(copy(trim(edit10.Text),length(trim(edit10.Text))-5,2)));//月
      DBNames := WebCn1.AppServer.GettableNames;
      if filename='B' then
        table_BG:='f_yBG'+year
      else if filename='P' then
        table_BG:='f_yPJ'+year
      else            //xml第一位必须为B或P
        begin
          showmessage('数据源有识,请重新选择正确的数据源!');
          edit10.SetFocus;
          exit;
        end;
      bg:='f';     if VarIsArray(DBNames) then  //判断对应年的表是否存在
        begin
          for i := 0 to VarArrayHighBound(DBNames, 1) do
            if table_BG=DBNames[i] then
              begin
                bg:='t';
                break;
              end;
         end;      if bg='f' then
         if filename='B' then
           begin
             showmessage(year+'年的火灾报告表不存在,请先到数据填报功能模块中建造!');
             exit;
           end
         else 
           begin
             showmessage(year+'年的执勤战斗报告表不存在,请先到数据填报功能模块中建造!');
             exit;
           end;   js_jibie:=0;//初始化      clientdataset3.Close;
      if filename='B' then        
        sql:='select 级别 from f_bSJBM where 类别='+quotedstr('单位编码')+' and 编码='+quotedstr(dwbm)+' order by 编码 asc'
      else 
        sql:='select 级别 from f_bSJBM where 类别='+quotedstr('消防队代码')+' and 编码='+quotedstr(dwbm)+' order by 编码 asc';
      
      webcn1.AppServer.getstr8(sql);
      clientdataset3.Open;
      js_jibie:=clientdataset3.FieldByName('级别').AsInteger;//*****这里出错,第一次接收xml数据时正确,第二次时则提示找不到"级别"这个字段
      clientdataset2.Close;
      if filename='B' then  //将数据库中对应时间段记录删除,再导入xml数据
        sql:='delete from f_yBG'+year+' where month(起火时间)>='+month1+' and month(起火时间)<='+month2+' and left(单位编码,'+inttostr(js_jibie*2)+')='+copy(dwbm,1,js_jibie*2)
      else
        sql:='delete from f_yPJ'+year+' where month(接警时间)>='+month1+' and month(接警时间)<='+month2+' and left(消防队代码,'+inttostr(js_jibie*2)+')='+copy(dwbm,1,js_jibie*2);
      webcn1.AppServer.update(sql);      clientdataset2.Close;//打开数据表,准备写入
      if filename='B' then
        sql:='select * from f_yBG'+year
      else
        sql:='select * from f_yPJ'+year
      webcn1.AppServer.update(sql);
      clientdataset2.Open;      num_ji:=0;
      clientdataset3.LoadFromFile(trim(edit10.Text));//导入xml文件到clientdataset3中
      clientdataset3.First;
      while not clientdataset3.Eof do
        begin
          num_ji:=num_ji+1;
          clientdataset2.Append;
          for i:=0 to clientdataset3.FieldCount-1 do
            clientdataset2.Fields[i].AsString:=clientdataset3.Fields[i].AsString;
          clientdataset2.ApplyUpdates(0);
          clientdataset3.Next;
        end;      edit10.Text:='';
      if filename='B' then
        showmessage('成功接收火灾记录'+inttostr(num_ji)+'条!')
      else
        showmessage('成功接收执勤战斗记录'+inttostr(num_ji)+'条!');

解决方案 »

  1.   

    可能问题就在通过LoadFromFile后,xml数据存入clientdataset3中无法释放,本例中第二次运行后,前面提取"级别"时,clientdataset3无法识别SQL语句,SQL语句本生没问题(第一次运行正常),问各位大侠帮助我,急,等着交工!!!
      我用的是三层结构,在服务器设置了函数getstr8(sql)、update(sql)。
      

  2.   

    为什么要xml呢?
    不是不可以,这样做太慢了吧!
    如果需要你是不是在服务端的ondatarequest没有做响应呀?
      

  3.   

    sql  server导出到access  
    ADOConnection  指向Access  
    SELECT  *  into  table    FROM  Tab1  IN  [ODBC]  
    [ODBC;Driver=SQL  Server;UID=sa;PWD=;Server=127.0.0.1;DataBase=Demo;]  ADOConnection  指向Access  
    SELECT * into aaa  FROM Tab1 IN [ODBC]
    [ODBC;Driver={Microsoft ODBC for Oracle};UID=oracle;PWD=oracle;SERVER=yourdata;]不知对你有帮助没有?