讀取Excel的記錄並匯入SQL資料庫

2021-09-08 22:52:03 字數 1816 閱讀 1215

準備一下,近段時間,需要把excel的資料匯入資料庫中。

引用命名空間:

using

system.configuration;

using

system.data;

using

system.data.oledb;

using system.data.sqlclient;

你可以寫乙個方法,是去讀取excel文件的方法,返回dataset資料集:

匯入資料庫,在資料庫中,需要建立乙個表來儲存excel匯入來的資料:

接下來,你可以使作sqlbulkcopy的方法進行複製資料庫:

演示:

下面內容於2017-10-17 14:38分新增:

使用sqldatareader來匯入,沒有做過多的測試,速度與dataset快不了多少:

sqlbulkcopy的方法:

使用NPOI讀取Excel資料並寫入SQLite

首先,我們來建乙個資料庫,我們就叫hello.db 不一定是db字尾,你可以sqlite,sqlite3,db3 都可以作為識別,然後往裡面建乙個空的 如下圖所示 然後建乙個excel 往 裡面寫入一些資料,我這裡只是demo形式,可以根據自己的實際情況,稍作修改 然後開始建乙個新的專案,我這裡用的...

python讀取excel並匯入mysql

如果excel檔案內的資料是這樣的 idname agebirthday 1kate 112008 2 2 2mike 221997 4 4 3tom 331986 5 5 首先,匯入python包xlrd,以及它的乙個方法 xldate as tuple。import xlrd from xlrd...

C 匯入Excel 讀取Excel方法總結

c 匯入excel 讀取excel方法總結 這種方法一般不用,因為他讀出來的是流,一般是轉成字串 如下 01 02 streamreader sr newstreamreader 檔名以及完整路徑 system.text.encoding.default stringdata sr.readtoen...