我要做一个备份的程序,用户可以选择要备份的时间段,其中涉及多表,我不知道如何把这些选择的记录插入到一个空的数据库里(我建了一个和原数据库结构一样的空的数据库)。各位高手一定要帮忙解答啊!我已经苦恼好几天了。

解决方案 »

  1.   

    你用的是MSSQL吧。
    你可以用
    INSERT INTO a.dbo.TABLE1
    SELECT *
    FROM table1
    注:a.dbo.table1   a为你的新数据库,table1 为你的对应的新表。
    还有:
    SELECT *
    FROM b.dbo.table1
    这样是查询另一个库里的记录。
    当然了,一定是这个用户对两个库都有权限访问的。
      

  2.   

    先过滤了,然后first,while not talbe.eod do begin 插入,table.next end
      

  3.   

    用两个ADOConnection。
    adoquery1.connection:=adoconnection1;//原数据库连接
    adocommand1.connection:=adoconnection2//目标数据库连接
    adoqeury1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('..........where ........')//写上你的过虑条件
    adoqeury1.open;
    while not adoquery1.eof do
      begin
       adocommand1.commandtext:='insert into '//写到目标表
       adocommand1.execute;
      adoquery1.next;
    end;
      

  4.   


    :(  ,我写的insert语句有错误吗?为什么还要报错啊?帮忙了
        
       query:=Tadoquery.Create(self);
        adocommand1:=TADOCommand.Create(self);
        query.ConnectionString:=ADOConnection.ConnectionString;
        adocommand1.ConnectionString:=adoconnectionbackup.ConnectionString;
       query.close;
       query.sql.clear;
       query.sql.add('select * from study where '+formatdatetime('yyyymmdd',strtodatetime(sdate))+'<=study_date and study_date<='+formatdatetime('yyyymmdd',strtodatetime(currdate))+'');
       query.open;
       query.first;
     while not query.eof do
      begin
       adocommand1.commandtext:='insert into study';
       adocommand1.Execute;
       query.next;
    end;