MSSQL:用openrowset增改查xls



1、查:

select * from openrowset(
'Microsoft.Jet.OLEDB.4.0',
'Excel 5.0;Database=d:/excel.xls;User ID=;Password=;',
'select * from [sheet1$]'


2、修改:(注意要先把ad hoc distributed queries 設爲1)

exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure


update openrowset(
'Microsoft.Jet.OLEDB.4.0',
'Excel 5.0;Database=d:/excel.xls;User ID=;Password=;',
'select * from [sheet1$]'
) set a='d'  where a='c'


3、插:

方法一:insert openrowset(
'Microsoft.Jet.OLEDB.4.0',
'Excel 5.0;Database=d:/excel.xls;User ID=;Password=;',
'select * from [sheet1$]'
) select 'aaa'

方法二:insert into openrowset(
'Microsoft.Jet.OLEDB.4.0',
'Excel 5.0;Database=d:/excel.xls;User ID=;Password=;',
'select * from [sheet1$]'
) values ('王進')




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章