如何用C#编程实现把DBF格式表导入到sql server2005中,找了一天了,也没有解决,请给详细代码,谢谢。

解决方案 »

  1.   

    sql="select * into T_TDD from openrowset('MSDASQL','Driver=Microsoft   Visual   FoxPro   Driver;SourceType=DBF;SourceDB="+sourse+"', 'select Ksh,Zkzh,xm from "+name+"') ";
    用上面的语句,出现如下错误
    SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。在网上找到如下解决方法 EXEC sp_configure 'show advanced options', 1 
    GO 
    RECONFIGURE 
    GO 
    EXEC sp_configure 'Ad Hoc Distributed Queries', 1 
    GO 
    RECONFIGURE 
    GO但问题仍没解决,还是出现同样的错误提示。我用sql 2005 express
    大侠们帮帮忙,有没有谁写过呀?
      

  2.   

    告诉你一个最快的方法,用SQLServer连接DBF
    在SQLServer中执行
    SELECT * into bmk
    FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
      'Data Source="e:\share";User ID=Admin;Password=;Extended properties=dBase 5.0')...bmk
    这样就可以把e:\share中的bmk.dbf表导入到Sqlserver中,
    速度是最快的
    上面这个方法DBF文件必须在服务器上,如果DBF不在服务器上,就用
    连接串
    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp;Extended Properties="dBase 5.0;";Persist Security Info=False
    SQL语句
    SELECT * into aaa IN [ODBC]
    [ODBC;Driver=SQL Server;UID=sa;PWD=;Server=127.0.0.1;DataBase=Demo;] 
    from aaa
    这是直接把客户端上的DBF传上服务器的最直接方法。把压箱底的方法都告诉大家
    在Form上放一个ADOConnection,连结指向目标Access库
    比如txt文件在c:\temp\aaaa.txt
    就执行
    ADOConnection.Connected := True;
    ADOConnection.Execute('Select * Into abcd From [Text;Database=c:\temp].aaaa.txt');
    就一切Ok了,这个方法一定行的,我好不容易才研究出来的
    有了这两个例子,异构数据库之间导数据的问题就举一反三,迎刃而解了。把Excel导入到Access中,同txt类似
    select * into <table name> from [excel 8.0;database=<filename>].[<sheetname>$]我最讨厌别人用BatchMove导数据了,明明一个SQL的事情,偏要
    我的目标是让大家抛弃BatchMoveProvider=MSDASQL.1;Extended Properties="Driver={Microsoft Visual Foxpro Driver};SourceType=DBF;SourceDB=你的文件所在路径;"  
    对access表得操作,从excel导入到access,成功 
    try
        if self.OpenDialog1.Execute then
          tmpdir := ExtractFilePath(self.OpenDialog1.FileName) + ExtractFileName(self.OpenDialog1.FileName);
        self.Caption := tmpdir;
        self.ADOConnection1.Connected:=true;
        self.ADOConnection1.Execute('insert into  aa(sid,sname,cname) select sid,sname,cname from [excel 8.0;database=' + tmpdir + '].[Sheet1$]');
       // self.ADOQuery1.Active := false;
       //self.ADOQuery1.SQL.Clear;
       // self.ADOQuery1.SQL.Add('select * into aa from [excel 8.0;database=' + tmpdir + '].[Sheet1$]');
       // self.ADOQuery1.Open;
      except
        showmessage('fail');
      end;  
    这些是标准的SQL导出语句:   select * into [Excel 8.0;database=导出目录].导出表名 from 表   select * into [FoxPro 2.6;database=导出目录].导出表名 from 表   select * into [FoxPro 2.5;database=同上].导出表名 from 表   select * into [dBase III;database=同上].导出表名 from 表   select * into [Paradox 4.X;database=同上].导出表名 from 表   select * into [;database=C:\temp\xxx.mdb].导出表名 from 表 
    Excel联接ADO串
    Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=E:\test\change.xls;Extended Properties=Excel 5.0;Persist Security Info=False
    --------------------------------------------------
    procedure TForm1.Button1Click(Sender: TObject);
    var
      sqltxt:String;
    begin
      Try
          sqltxt:='SELECT * into newtable FROM OpenDataSource(Microsoft.Jet.OLEDB.4.0,Data Source="E:\test\change.xls";User ID=Admin;Password=;Extended properties=Excel 5.0)...xactions';      ADOConnetion1.Close;
          ADOConnetion1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=E:\test\change.xls;Extended Properties=Excel 8.0;Persist Security Info=False';
          ADOConnetion1.Execute(sqltxt);
          Application.MessageBox('数据导出成功','系统信息',MB_OK+MB_IconInformation);
        except
          Application.MessageBox('数据导出失败','系统信息',MB_OK+MB_IconError);
        end;    ADOConnetion1.Close;end;
      

  3.   

    我最讨厌别人用BatchMove导数据了这些是标准的SQL导出语句:   select * into [Excel 8.0;database=导出目录].导出表名 from 表 ------------------
    这个要看情况的,只有MS自己的产品所以才扩展了sql语法来支持ODBC数据源,换成是oracle中执行这个sql怎么可能成功?batch 倒数据有时候在c/s结构下还是需要,否则服务器上执行的sql没法读取client端文件时怎么处理?