/***
** System:window7
** DB:MsSQLServer2005
** dbFile:2003 Excel
**/
/** 注意事项:
** 1. 以管理员身份登录SQL Server 外围应用配置器,然后点击功能外围应用配置器选中
** 既席远程调用和ole自动化
** 2. 重新启动mssqlserver 服务
** 3. 确保dbfile文件处于非活动状态(不要打开或有程序在读)
** 4.确保dbfile的列数与表结构一致
**/
exec
sp_configure
'show advanced options'
,1
reconfigure
exec
sp_configure
'Ad Hoc Distributed Queries'
,1
reconfigure
EXEC
sp_configure
'show advanced options'
, 1
GO
RECONFIGURE
GO
EXEC
sp_configure
'Ad Hoc Distributed Queries'
, 1
GO
RECONFIGURE
GO
prconfigure
create
table
student
(
id
int
identity
primary
key
,
name
varchar
(50) ,
sex tinyint,
mark
varchar
(50)
)
insert
into
student(
name
,sex,mark)
SELECT
*
from
OPENROWSET(
'MICROSOFT.JET.OLEDB.4.0'
,
'Excel 5.0;HDR=YES;DATABASE=e:\\testdata.xls'
,sheet1$) ;
select
*
from
student ;