將excel檔案匯入到winform的控制項中

2021-05-21 19:11:17 字數 934 閱讀 7613

將excel檔案匯入到winform的控制項中

要新增引用com中的microsoft.office.core

然後新增命名空間system.data.oledb;

public partial class form1 : form

///

/// 從選擇的excel匯入

///

///

public void importexcel(string excelname,string tablename)

oledbconnection odcon = new oledbconnection(strcon);//建立連線

odcon.open();//開啟連線

迴圈輸出顯示到控制項中

//oledbcommand odc = new oledbcommand("select * from " + tablename, odcon);

//oledbdatareader dr = odc.executereader();

//while (dr.read())

////把資料集dataset放到控制項中顯示

oledbdataadapter odda = new oledbdataadapter("select * from " + tablename, odcon);

dataset ds = new dataset();

trycatch(exception ex)

if (ds != null)

else}

private void button1_click(object sender, eventargs e)}}

2 表名不能寫成"sheet1",這樣會出錯

將Excel匯入到Oracle

private void btninsert click object sender,eventargs e dataset ds 插入資料庫方法 private void insertdbmeth 如果查到了資料,才使控制分頁按鈕生效 if odr 0 conn.close catch excep...

將Excel資料匯入到SQL Server資料庫中

1 接受資料匯入的表已經存在。insert into t1 select from openrowset microsoft.jet.oledb.4.0 excel 5.0 hdr yes database c test.xls sheet1 2 匯入資料並生成表。select into t1 fr...

將Excel資料匯入到SQL Server資料庫中

這個方法是到目前為止我見到最好的方法,還有幾個要注意的問題也在下面提到了哦!其中還涉及到要注意到地方都在下面累出來了 1 接受資料匯入的表已經存在。insert into t1 select from openrowset microsoft.jet.oledb.4.0 excel 5.0 hdr ...