关于利用opendatasource 读取excel文件中的数据问题以及更新数据库中对应数据的问题

<strong>前言:</strong>
   <strong> 由于下面是根据别人的提问解决过程的一个回顾总结,若碰到类似问题,按照下面步骤不能解决,并找到了解决办法的朋友,欢迎补充!</strong>
/*
    操作系统:win7 32位处理器
    Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86) 
	Oct 14 2005 00:33:37 
	Copyright (c) 1988-2005 Microsoft Corporation
	Developer Edition on Windows NT 6.1 (Build 7601: Service Pack 1)

       excel 为2010
*/

--1.<strong>设置sqlserver configuration manager->功能的外围应用配置器开启 openrowset和opendatasource功能</strong>

--2.<strong>设置参数值为非空(分别为允许进程和动态参数)</strong>
USE [master]    
GO    
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1    
GO    
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1    
GO    

或者
<strong>management studio->服务器对象->链接服务器->访问接口</strong>


select * from OPENDATASOURCE(     --openrowset()同样也可以用来访问本机中excel中的数据
         'Microsoft.Ace.OleDb.12.0',  --EXCEL版本为2010及以上版本可用,如果是2007及以下版本可用microsoft.jet.oled.4.0
         'Extended Properties="Excel 12.0;HDR=YES;IMEX=1";Data Source="E:\test.xlsx"'  
         )...[test$]
或者
select * from opendatasource('Microsoft.ace.oledb.12.0', 'Excel 8.0;Database=e:\test.xlsx')...[test$]   


--<strong>使用opendatasource更新数据库中的表</strong>
update t1 set name=a.sname
from (select * from    OPENDATASOURCE(  
         'Microsoft.Ace.OleDb.12.0',  
         'Extended Properties="Excel 12.0;HDR=YES;IMEX=1";Data Source="E:\test.xlsx"'  
         )...[test$]  ) a where t1.id=a.id


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值