EXECL,文字檔案匯入資料庫的程式

2021-04-09 02:14:03 字數 937 閱讀 4115

///   功能:讀取excel檔案,返乙個datatable

///   日期:2004-10-20

///  

///   檔案

///   第一列是否為列名,一般為0或1

///  

[stathread]

public   static   datatable   readecxel(string   filename,int   rows)

else

oledbconnection   cn   =   new   oledbconnection();

cn.connectionstring   =   sconnectionstring;

cn.open();

string   strsql   =   "select   *   from   [sheet1$]";

system.data.oledb.oledbdataadapter   da=new   system.data.oledb.oledbdataadapter(strsql,cn);

da.fill(dt);

cn.close();

return   dt;

/*用datareader方式!

oledbcommand   cmd   =   cn.createcommand();

cmd.commandtext   =   ssql;

oledbdatareader   dr   =   cmd.executereader();

while(dr.read())*/}

/導檔案

bulk insert      dbo.table1

from          'f:/wwwroot/website2/1.txt' with (fieldterminator = ',', rowterminator = '/n') 

MSSQLSERVER資料庫 匯入文字檔案

有時候需要把文字檔案根據一定的格式批量匯入資料庫,mssqlserver提供了這樣的匯入語句 bulk insert ebss.mss actingwork ml from c 表資料 mss actingwork ml.txt with fieldterminator rowterminator ...

文字檔案資料匯入SQL Server資料庫

阿斯頓 12 周小川 14 東豐閣 15 using system using system.collections.generic using system.linq using system.text using system.windows using system.windows.contr...

從文字檔案匯入資料到資料庫表

最近一直在使用常用資料庫的資料匯入,這裡把已經用到的匯入命令先簡要列舉一下 不介紹每乙個option的具體意義,如果你用到了,請直接msdn檢視具體option的意義,此處不再贅述!bulk insert erp users from d rows 1m.txt with datafiletype ...