偶现在有个任务,要把EXCEL中的数据导入到ACCESS中的指定表中。各位给提供个建议,采用哪种方法比较可行。

解决方案 »

  1.   

    不行啊,我的可能比较复杂,比如,在EXCEL中,我要有选择的把数据导入到ACCESS中指定的表中。
      

  2.   

    ACCESS可以直接导入EXCEL表格,不用另外的程序。
      

  3.   

    ADOConnection1.Execute('SELECT * into  ' + tablename+ ' FROM [excel 8.0;database='
          + filename+ '].[' + sheetsname + ']');这段代码将指定excel文件中的指定工作簿导入到数据库中的指定表中,前提是这个表不存在。不知是不是符合。
      

  4.   

    function TForm1.ExcelToAccess;
    var
        StrSQL:string;
        filename:string;
    begin
        filename:=opendialog1.FileName;    //打开目标Access数据库    adoconnection2.Close;
        adoconnection2.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+opendialog2.FileName+';Persist Security Info=False';
        //delete the table if it is exists
        StrSQL:='drop table Customer';
        try
            adoconnection2.Connected:=false;
            adoconnection2.Execute(StrSQL);
            adoconnection2.Connected:=true;
        except
        end;
        StrSQL:='select * into Customer FROM [Excel 8.0;database='+filename+'].['Sheet1$]';    //这里的'Sheet1'是在Excel中的表名
        try
            adoconnection2.Connected:=false;
            adoconnection2.Execute(StrSQL);
            adoconnection2.Connected:=true;
            adoconnection2.Connected:=false;
            messagebox(handle,'The table has been pumped successful!','information',mb_ok or mb_iconinformation);
            result:=true;
        except
            on e:exception do
            begin
                messagebox(handle,pchar(e.Message),'information',mb_ok or mb_iconerror);
                adoconnection2.Connected:=false;
                result:=false;
            end;
        end;
    end;
      

  5.   

    StrSQL:='select * into Customer FROM [Excel 8.0;database='+filename+'].[Sheet1$]';
    因为是手写出来的,上面的代码改成如上的,本来多了一个单引号