Following experts and sharing my experience

To import data from excel to DB

上一篇 / 下一篇  2008-09-25 15:33:05 / 个人分类:SQL Server

Here,I introduce some methods to import data from excel to DB,

1  By OPENDATASOURCE

SELECT
*FROM OPENDATASOURCE(
   'Microsoft.Jet.OLEDB.4.0',
   'Excel 8.0;DataBase=D:\TEST.xls')...[sheet1$]

Note: Sometimes, error message will occor when executing above script. like this:
Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.

The solution issettingAd Hoc Distributed Queriesto1,you can refer to my post:http://www.cnblogs.com/Burgess/archive/2008/09/24/1298195.html


2   By Linked server

EXECsp_addlinkedserver --add linked server
    @server = N'MyExcel',
    @srvproduct = N'Jet 4.0',
    @provider = N'Microsoft.Jet.OLEDB.4.0',
    @datasrc = N'd:\TEST.xls',
    @provstr = N'Excel 8.0'
GO

Note:You can also add linked server by below method:

execsp_addlinkedsrvlogin'MyExcel','false'--login without account (Optional)
go

select* from MyExcel...sheet1$ --query data
go

 

 3  By VBA

 

Code


 4   By SQL Server Import and Export Wizard
Detailed oprating steps isabbreviated here.

5  Other methods:
Please refer tohttp://support.microsoft.com/default.aspx/kb/321686

 


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

我的栏目

日历

« 2012-05-24  
  12345
6789101112
13141516171819
20212223242526
2728293031  

我的存档

数据统计

  • 访问量: 443
  • 日志数: 21
  • 建立时间: 2008-09-05
  • 更新时间: 2008-09-25

RSS订阅

Open Toolbar