ado的奇怪问题,多步操作产生错误,请检查每一步状态值

时间:2021-12-01 08:41:09
http://www.studysea.net/  ,总站
http://www.studysea.net/  ,delphi站
http://vod.studysea.net/  ,影视站
刚刚开张,请大家过来看看啊
刚刚开张,更需要大家的支持和鼓励,更希望大家不要只下载电影,希望大家能帮助一下学海,让学海成为大家的知识宝库

procedure ote_work.Execute;
var
  ExcelApp: Variant;
  filename,oracle_user,oracle_password,temp_path:String;
  i,j,k:integer;
  Int_datebase:Array[0..7] of String;
begin
  with Form1 do
  begin
    filename:=ExtractFilePath(paramstr(0))+'myini.ini';
    myinifile:=TInifile.Create(filename);
    Int_datebase[0]:=myinifile.readstring('oracle','oracle_sj','无');
    Int_datebase[1]:=myinifile.readstring('oracle','oracle_wj','无');
    Int_datebase[2]:=myinifile.readstring('oracle','oracle_tl','无');
    Int_datebase[3]:=myinifile.readstring('oracle','oracle_ly','无');
    Int_datebase[4]:=myinifile.readstring('oracle','oracle_zl','无');
    Int_datebase[5]:=myinifile.readstring('oracle','oracle_jt','无');
    Int_datebase[6]:=myinifile.readstring('oracle','oracle_xq','无');
    Int_datebase[7]:=myinifile.readstring('oracle','oracle_qsy','无');
    oracle_user:=myinifile.readstring('oracle','oracle_user','无');
    oracle_password:=myinifile.readstring('oracle','oracle_password','无');
    myinifile.Destroy;

    Application.Initialize;
    //CoInitialize(nil);
    //Provider=OraOLEDB.Oracle.1;Password=test;Persist Security Info=True;User ID=test;Data Source=yb;Extended Properties=""
    for k:=1 to 1 do
    begin
      case k of
        0:temp_path:=path+'sj\';
        1:temp_path:=path+'wj\';
        2:temp_path:=path+'tl\';
        3:temp_path:=path+'ly\';
        4:temp_path:=path+'zl\';
        5:temp_path:=path+'jt\';
        6:temp_path:=path+'xq\';
        7:temp_path:=path+'qsy\';
      end;

      g_fun_CreateTempDirectory(temp_path);

      ADOQuery1.Active:=false;
      ADOQuery1.Close;              
      ADOConnection1.Close;
      ADOConnection1.Connected:=false;
      //ADOConnection1.ConnectionString:='Provider=OraOLEDB.Oracle.1;Password='''+oracle_password+''';Persist Security Info=True;User ID='''+oracle_user+''';Data Source='''+Int_datebase[k]+''';Extended Properties=""';
      ADOConnection1.ConnectionString:='Provider=MSDAORA.1;Password=pender412;User ID=baisadmin;Data Source=wjbais;Persist Security Info=True';
      ADOQuery1.SQL.Text:='select a.reg_no reg_no,a.corp_china_name corp_china_name,d.chin_name oper_man,a.writeoff_date writeoff_date, ';
      ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+' c.value writeoff_reason,e.name offer_unit,sysdate offer_date  ';
      ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+' from t_corp_hist a,t_main_writeoff b,';
      ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+' (select code,value from t_dictionary where code_name like ''注销原因'') c,t_person d,';
      ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+' t_unit e ';
      ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+' where a.admit_no=b.admit_no and a.corp_status =''03'' and  b.main_reason=c.code  and a.oper_main_no=d.main_no';
      ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+' and  a.belong_unit=e.unit_no and trim(a.reg_no) is not null ';
      ADOQuery1.Open;
      ADOQuery1.Active:=true;
      ExcelApp := CreateOleObject('Excel.Application');
      ExcelApp.workbooks.add; //添加工作表
      i:=2;
      ExcelApp.Cells[1,1].Value:='REG_NO';             
      ExcelApp.Cells[1,2].Value:='CORP_CHINA_NAME';
      ExcelApp.Cells[1,3].Value:='OPER_MAN';
      ExcelApp.Cells[1,4].Value:='WRITEOFF_DATE';
      ExcelApp.Cells[1,5].Value:='WRITEOFF_REASON';
      ExcelApp.Cells[1,6].Value:='OFFER_UNIT';
      ExcelApp.Cells[1,7].Value:='OFFER_DATE';
      j:=ADOQuery1.RecordCount;
      while ADOQuery1.Eof=false do
      begin
        ExcelApp.Cells[i,1].Value:=ADOQuery1.Fields[0].Value;
        ExcelApp.Cells[i,2].Value:=ADOQuery1.Fields[1].Value;
        ExcelApp.Cells[i,3].Value:=ADOQuery1.Fields[2].Value;
        ExcelApp.Cells[i,4].Value:=ADOQuery1.Fields[3].Value;
        ExcelApp.Cells[i,5].Value:=ADOQuery1.Fields[4].Value;
        ExcelApp.Cells[i,6].Value:=ADOQuery1.Fields[5].Value;
        ExcelApp.Cells[i,7].Value:=ADOQuery1.Fields[6].Value;

        StatusBar1.Panels.Items[0].Text:=IntToStr(i);
        StatusBar1.Panels.Items[1].Text:=IntToStr(j);
        ProgressBar1.Position:=Round(100*(i/j));;
        i:=i+1;
        ADOQuery1.Next
      end;
      ADOQuery1.Active:=false;
      ADOQuery1.Close;
      ADOConnection1.Close;
      filename:=temp_path+'t_corp_writeoff.xls';
      ExcelApp.workbooks[1].saveas(filename);
      //ExcelApp.close;
      ExcelApp.Quit;
      //CoUnInitialize;
      //showmessage(Path);
    end;
  end;
  //showmessage('导库成功');
end;

很奇怪的问题,请大家看看,我百思不得其解,我用了多线程

ExcelApp.Cells[i,4].Value:=ADOQuery1.Fields[3].Value;
把这句去掉就不会出现这种错误了,请高手解答,谢谢    

6 个解决方案

#1


是不是你的值不匹配?

#2


ExcelApp.Cells[i,4].Value:=ADOQuery1.Fields[3].astring;

#3


没有用啊

#4


是不是数据有问题,这样看一下
var
  str : string;

....

str:=ADOQuery1.Fields[3].astring;
showmessage(str);

#5


我想应该是类型之间的不匹配

#6


类型不匹配所置

#1


是不是你的值不匹配?

#2


ExcelApp.Cells[i,4].Value:=ADOQuery1.Fields[3].astring;

#3


没有用啊

#4


是不是数据有问题,这样看一下
var
  str : string;

....

str:=ADOQuery1.Fields[3].astring;
showmessage(str);

#5


我想应该是类型之间的不匹配

#6


类型不匹配所置