當前位置:編程學習大全網 - 編程軟體 - C#.NETExcel文件數據導入SQLServer數據庫完整代碼?

C#.NETExcel文件數據導入SQLServer數據庫完整代碼?

--如果導入數據並生成表

select*into表from

OPENROWSET('MICROSOFT.JET.OLEDB.4.0'

,'Excel5.0;HDR=YES;DATABASE=c: est.xls',sheet1$)

===

--將某個目錄上的Excel表,導入到數據庫中

--將所有的Excel文件放到壹個目錄中,假設為c: est,然後用下面的方法來做

createtable#t(fnamevarchar(260),depthint,isfbit)

insertinto#texecmaster..xp_dirtree'c: est',1,1

declaretbcursorforselectfn='c: est'+fnamefrom#t

whereisf=1andfnamelike'%.xls'--取.xls文件(EXCEL)

declare@fnvarchar(8000)

opentb

fetchnextfromtbinto@fn

while@@fetch_status=0

begin

--下面是查詢語句,需要根據妳的情況改為插入語句

--插入已有的表用:insertinto表selct*from...

--創建表用:select*into表from...

set@fn='select*from

OPENROWSET(''MICROSOFT.JET.OLEDB.4.0'',''Excel5.0;HDR=YES;DATABASE='+@fn+''',全部客戶$)'

exec(@fn)

fetchnextfromtbinto@fn

end

closetb

deallocatetb

droptable#t

  • 上一篇:太原批發市場在哪裏?
  • 下一篇:徐州金文大族激光設備有限公司怎麽樣?
  • copyright 2024編程學習大全網