我是刚学习用odac连接oracle数据库的,想实现dbf和oracle数据库之间的导入导出功能, 怎么办哟,请各位大侠多多帮忙哈.

解决方案 »

  1.   

    procedure TfcdrdcF.ImpFromDbf;
    var
      i: Integer;
      str: string;
      fdr: boolean;
    begin
      fdr := False;
      DataBase2.Close;
      CreateAlias('yqcb_dbf', DirectoryListBox1.Directory);
      DataBase2.Open;
      Gauge1.MaxValue := FileListBox1.SelCount - 1;
      for i := 0 to (FileListBox1.Items.Count - 1) do
      begin
        try
          if FileListBox1.Selected[i] then
          begin
            desfile := FileListBox1.Items.Strings[i];
            delete(desfile, 1, 10);
            delete(desfile, length(desfile) - 3, 4);
            shortName := desfile;
            str := copy(FileListBox1.Items.Strings[i], 5, 4) + '-' + copy(FileListBox1.Items.Strings[i], 9, 2) + '-' + '15';
            if str <> (fsys_date) then
              if MessageDlg('导入表' + #39 + shortName + #39 + '的日期和系统日期不同,是否继续导入', mtConfirmation,
                [mbYes, mbNo], 0) = mrYes then continue
              else break;
            if SQlCount(dataBase1.DatabaseName, 'SELECT TABLENAME FROM CBBDIR WHERE TABLENAME=' + #39 + shortName + #39) = 1 then
            begin
              Label3.Caption := '正在导入' + ShortName;
              Label3.Refresh;
              Gauge1.Progress := i;
              Impdata(DataBase1.DatabaseName, FileListBox1.Items.Strings[i]);
            end;
            fdr := True;
          end;
        except
          raise Exception.Create('导入数据失败:');
        end;
      end;
      if fdr = True then
      begin
        MessageDlg('成功导入数据!', mtInformation, [mbok], 0);
        Gauge1.Progress := 0;
      end;
    end;
      

  2.   

    procedure TfcdrdcF.ExpToDbf;
    var
      TmpQuery: Tquery;
      i, FileCount: Integer;
      str: string;
    begin
      TmpQuery := TQuery.Create(nil);
      DataBase2.Close;
      CreateAlias('yqcb_dbf', DirectoryListBox1.Directory);
      DataBase2.Open;
      str := 'SELECT TABLENAME FROM CBBDIR WHERE SX=''输出表'' AND TABLENAME IS NOT NULL ORDER BY TABLENAME';
      TmpQuery.DatabaseName := Database1.DatabaseName;
      TmpQuery.SQL.Text := str;
      TmpQuery.Open;
      FileCount := TmpQuery.RecordCount;
      Gauge1.MaxValue := FileCount - 1;
      for i := 0 to FileCount - 1 do
      begin
        Label3.Caption := '正在导出' + TmpQuery.Fields[0].AsString;
        Panel1.Refresh;
        Gauge1.Progress := i;
        bm(TmpQuery.Fields[0].AsString); //batchMove
        TmpQuery.Next;
      end;
      MessageBox(handle, '成功导出数据!', '系统信息', mb_ok);
      Gauge1.Progress := 0;
      Label3.Caption := '';
      TmpQuery.Free;
    end;