我有两个完全一样的access数据库(access1与access2),而且其内所有表的结构都是完全一样的,
  我现在想将access1中的aa表所有记录导入到access2中aa表内,请问如何编写程序??(我启动程序时打开的是access2数据库和aa表,用的是tabel控件;我导入时对access1数据库的aa表用的是adoquery和adoconnect控件。但是出错,我的程序如下:) ADOConnection1.connected:=false;
 ADOConnection1.connectionstring:='Provider=MSDASQL.1;Password="";Persist Security Info=True;Data Source=access1';
  with adoquery1 do
       begin
           close;
           sql.clear;
           sql.Add('select * from caifz');
           open;
           first;
       end;
  with adoquery1 do
       begin
           adoquery1.first;
           table1.active:=true;
           table1.Edit;
           repeat
              begin
                 table1.fieldbyname('bianhao').asstring:=adoquery1.fieldbyname('bianhao').asstring;
                 table1.FieldByName('danwei').asstring:=adoquery1.fieldbyname('danwei').asstring;
                 table1.fieldbyname('cai').AsString:=adoquery1.fieldbyname('cai').AsString;
                 post;
                 next;
              end;
           until eof;
       end;

解决方案 »

  1.   

    覆盖数据
    select * into table from table 或者你可以直接调用sql server 的导入导出工具
      

  2.   

    我倒了
    1 post;应该是table1.post和table.next
    你这样用是对adoquery1
    2 你可以直接用一句sql就搞定阿,比如
    INSERT INTO Customers2
     SELECT CustomerID
    FROM Customers1
    IN OtherDB.mdb 
    WHERE CustomerID Like "A*"; 
      

  3.   

    谢谢 firetoucher 朋友  第二条能否说一下您的各个参数含义
      

  4.   

    对就得append->post;一条一条导
      

  5.   

    sql语句,看看jet sql帮助吧INSERT INTO 要插入数据的表名
     SELECT 字段列表
    FROM 数据源表名
    IN 数据源表名所在数据库
    WHERE 需要倒入的记录集的条件; 
      

  6.   

    我用以下语句导入时出错
      jishu:=0;
      ADOConnection1.connected:=false;
      ADOConnection1.connectionstring:='Provider=MSDASQL.1;Password="";Persist Security Info=True;Data Source=mucai_back';
      with adoquery1 do
           begin
               close;
               sql.clear;
               sql.Add('select * from caifz');
               open;
               last;
           end;
       with table1 do
           begin
               adoquery1.first;
               table1.active:=true;
               repeat
                  if locate('hao',adoquery1.fieldbyname('hao').asstring,[]) then
                        adoquery1.next;
                  else
                     begin
                        table1.append;
                        table1.Edit;
                        table1.fieldbyname('fayue').AsString:=adoquery1.fieldbyname('fayue').AsString;
                        table1.fieldbyname('fari').AsString:=adoquery1.fieldbyname('fari').AsString;
                        table1.FieldByName('dayin').AsString:=adoquery1.fieldbyname('dayin').asstring;
                        table1.post;
                        table1.Next;
                        jishu:=jishu+1;
                     end;
               until eof;
               showmessage('此项操作将向本地数据库内导入 '+inttostr(jishu)+' 条数据记录!');
           end;
      ADOConnection1.connected:=false;
      

  7.   

    转贴:
     在 数 据 库 应 用 系 统 中, 常 常 要 对 数 据 进 行 成 批 的 如 追 加、 删 除、 更 改 等 操 作, 这 种 批 量 操 作 在 专 门 的 数 据 库 开 发 工 具 如VFP 中 用APPEND 、COPY 命 令 带 上 相 应 的 命 令 子 句 就 能 轻 易 完 成。 但 在 其 它 开 发 工 具 中 并 没 有 类 似 的 命 令, 而 是 提 供 能 完 成 类 似 功 能 的 控 件 或 对 象, 如 在PowerBuilder 中 就 是 利 用Pipe Line( 数 据 管 道) 来 完 成 两 个 或 同 构 或 不 同 构 的 表 之 间 的 数 据 批 处 理。 本 文 要 介 绍 的 是Delphi 中 用 来 完 成 数 据 批 处 理 任 务 的 组 件TBatchMove。TBatchMove 组 件 能 够:  
        (1)将 一 个 数 据 集 中 的 数 据 追 加 到 一 个 表 中。.  
        (2)从 一 个 表 中 删 除 满 足 条 件 的 记 录。  
        (3)按 旧 表 结 构 生 成 一 个 新 表, 若 欲 生 成 的 新 表 已 存 在, 则 覆 盖。       具 体 的 操 作 要 通 过 设 置TBatchMove 的Mode 属 性 后 再 调 用Execute 方 法 来 完 成。 为 举 例 说 明 问 题, 我 们 在 别 名 数 据 库DBDEMOS 中 先 创 建 两 个dBase 格 式 的 表Test1.dbf 和Test2.dbf。 二 者 的 结 构 如 下 表: 
          Test1.dbf         Test2.dbf 
            Name C 10 Name C 10 
            Code C 3 Code C 3          其 中 表Test2.dbf 在 字 段code 上 建 立 有 唯 一 索 引。 同 时 假 设 表 单 中 已 有 两 个TABLE 控 件Tsource 和Tdest 和 一 个TbatchMove 组 件batchmove1。Tsource 和Tdest 的DatabaseName 属 性 均 设 为DBDEMOS。batchmove1 的source 属 性 设 为Tsource,destination 属 性 设 为Tdest。       在 使 用TbatchMove 组 件 时, 必 须 牢 记: 所 有 的 操 作 都 是 以 源 表 为 标 准 针 对 目 的 表 进 行 的, 下 面 就 分 别 举 例 说 明TbatchMove 的 各 种 操 作 模 式:  
        (1)batAppend 追 加 模 式 将 源 表 中 的 数 据 追 加 到 目 的 表 中, 目 的 表 必 须 事 先 存 在。 这 是 缺 省 模 式。  
        batchmove1.source=Tsource;  
        batchmove1.destination=Tdest2 ;  
        batchmove1.Mode:=batAppend;  
        batchmove1.Execute;  
        (2)batUpdate 更 新 模 式 用 源 表 中 匹 配 目 的 表 的 记 录 替 换 目 的 表 中 的 相 应 记 录。 目 的 表 必 须 事 先 存 在 且 有 一 已 定 义 的 索 引 用 来 匹 配 源 表 中 的 记 录。  
        Tdest.IndexFieldNames:='code';  
        batchmove1.source=Tsource;  
        batchmove1.destination=Tdest ;  
        batchmove1.Mode:=batUpdate;  
        batchmove1.Execute;  
        (3)batAppendUpdate 追 加 更 新 模 式 如 果 源 表 中 有 与 目 的 表 匹 配 的 记 录, 则 替 换 目 的 表 记 录, 否 则, 直 接 追 加 到 目 的 表 中。 目 的 表 必 须 事 先 存 在 且 有 一 已 定 义 的 索 引 用 来 匹 配 源 表 中 的 记 录。  
        Tdest.IndexFieldNames:='code';  
        batchmove1.source=Tsource;  
        batchmove1.destination=Tdest ;  
        batchmove1.Mode:=batAppendUpdate;  
        batchmove1.Execute;  
        (4)batCopy 拷 贝 模 式 按 源 表 结 构 生 成 新 表, 源 表 中 的 数 据 同 时 拷 贝 到 目 的 新 表 中。 如 果 要 生 成 的 新 表 已 存 在, 则 覆 盖。  
    // 按Test1.dbf 生 成 新 表xxx.dbf  
    // 如 果 不 指 定 扩 展 名dbf, 生 成 的 新 表 将 是Paradox 格 式 的xxx.db。  
        Tdest.TableName:='xxx.dbf';  
        batchmove1.source=Tsource;  
        batchmove1.destination=Tdest ;  
        batchmove1.Mode:=batCopy;  
        batchmove1.Execute;  
        (5)batDelete 删 除 模 式 删 除 目 的 表 中 与 源 表 匹 配 的 记 录。 目 的 表 必 须 事 先 存 在 且 有 一 已 定 义 的 索 引 用 来 匹 配 源 表 中 的 记 录。  
        Tdest.IndexFieldNames:='code';  
        batchmove1.source=Tsource;  
        batchmove1.destination=Tdest ;  
        batchmove1.Mode:=batDelete;  
        batchmove1.Execute;       TBatchMove 还 有 一 个 重 要 属 性ChangedTableName, 在 实 际 运 用 中, 通 过 指 定ChangedTableName 属 性 可 以 创 建 一 个Paradox 表, 该 表 用 来 保 存 目 的 表 中 被 更 改 数 据 的 原 始 备 份, 有 了 这 个 备 份 表 就 可 以 确 保 恢 复 目 的 表 中 的 数 据。       顺 便 提 一 句, 如 果 要 删 除 某 一 个 表 中 的 全 部 记 录, 可 以 采 用Table 组 件 的EmptyTable 方 法, 例 如Tdest.EmptyTable 将 清 空Tdest 所 指 定 的 表test2.dbf。       本 文 中 是 以 同 构 的dbf 表 进 行 的 示 例, 在 实 际 运 用 中, 源 表 和 目 的 表 可 能 同 购, 也 可 能 异 构, 异 构 时,Delphi 的BDE 会 自 动 进 行 类 型 和 长 度 上 的 转 换, 具 体 类 型 间 的 关 系 可 以 有 关BDE 的 帮 助。 本 文 中 各 种 操 作 模 式 的 实 际 结 果 均 可 以 从Delphi 的Database Desktop 中 查 看 到 
      

  8.   

    table1.post;
     table1.Next;
    __________________
    你想干什么?应该在添加完了以后,循环外再post,