Excel匯入SQL方法

2021-08-31 12:18:05 字數 1538 閱讀 3462

很簡單的一句話就可以了:

insert

into hhltest(a,b,c)

select a,b,c from

openrowset

('microsoft.jet.oledb.4.0'

,'excel 5.0;hdr=yes;database=c:/hhltest.xls'

,sheet1$)

備註:測試環境:

sql server 2005 , excel 2007

結果提示1:

sql server

阻止了對元件

'ad hoc distributed queries'

的statement'openrowset/opendatasource'

的訪問,因為此元件已作為此伺服器安全配置的一部分而被關閉。系統管理員可以通過使用

sp_configure

啟用'ad hoc distributed queries'

。有關啟用

'ad hocdistributed queries'

的詳細資訊,請參閱

sql server

聯機叢書中的

"外圍應用配置器"。

解決方法:

啟用ad hoc distributed queries

:exec sp_configure 'show advanced options',1

reconfigure

exec sp_configure 'ad hoc distributed queries',1

reconfigure

使用完成後,關閉

ad hoc distributed queries

:exec sp_configure 'ad hoc distributed queries',0

reconfigure

exec sp_configure 'show advanced options',0

reconfigure

結果提示2:

鏈結伺服器

"(null)"

的ole db

訪問介面

"microsoft.jet.oledb.4.0"

返回了訊息

"未指定的錯誤

"。訊息

7303

,級別16

,狀態1

,第1

行無法初始化鏈結伺服器

"(null)"

的ole db

訪問介面

"microsoft.jet.oledb.4.0"

的資料來源物件

解決辦法:

1、檔案是不是加密碼了2、

xls要關閉,不能開啟

3、是否允許

opendatasource 支援4

、你是2005

還是2000

?更改properties=excel 8.0'

裡的版本,換大點

5、啟動

opendatasource

,如下圖

更多:

EXCEL資料匯入SQL表的方法

1 建立與資料庫配對的excel資料表 2 在sql中獲取插入語句指令碼整理出橙色欄位的格式 3 每個資料字段轉換成符合sql格式的資料,如 藍色部分 4 再把藍色部分的資料以逗號間隔連線在一起 5 把橙色部分和黃色部分鏈結形成黃色部分的最終插入語句 6 把黃色部分複製貼上到查詢分析器並執行就匯入成...

SQL語句匯入匯出Excel

匯出到excel exec master.xp cmdshell bcp settledb.dbo.shanghu out c temp1.xls c q s gnetdata gnetdata u sa p 匯入excel select from opendatasource microsoft....

sql匯入匯出 excel檔案

在企業管理器的匯入一步步操作或用 語句如下 從excel檔案中,匯入資料到sql資料庫中,很簡單,直接用下面的語句 在開始前需要啟用ad hoc distributed queries exec sp configure show advanced options 1 reconfigure exe...