方法一:
string strcon = "provider=microsoft.jet.oledb.4.0;data source=" + strsource + ";extended properties=excel 8.0";
string query = "select * from [sheet1$]";//sheet1表示表
oledbconnection olecon=new oledbconnection(strcon);
oledbcommand olecommand = new oledbcommand(query, olecon);
oledbdataadapter oleadapter = new oledbdataadapter(olecommand);
dataset ds = new dataset();
// 將 excel 的[sheet1]表內容填充到 dataset 物件
oleadapter.fill(ds);
// 資料繫結
datagrid1.datasource=ds;
datagrid1.databind();
}方法二:(與一相差不大)
string strsource = file1.value;
string connstr = "provider=microsoft.jet.oledb.4.0;data source=" + strsource + ";extended properties=excel 8.0";
string query = "select * from [sheet1$]";//sheet1表示表
oledbcommand olecommand = new oledbcommand(query, new oledbconnection(connstr));
oledbdataadapter oleadapter = new oledbdataadapter(olecommand);
dataset mydataset = new dataset();
// 將 excel 的[sheet1]表內容填充到 dataset 物件
oleadapter.fill(mydataset, "[sheet1$]");
// 資料繫結
datagrid1.datasource = mydataset;
datagrid1.datamember = "[sheet1$]";
datagrid1.databind();
Excel資料匯入到Access
下面是asp的全部程式,需要做的是建乙個test.mdb資料庫和乙個test.xls的excel 查詢excel準備匯入到access sql select from sheet1 要匯入的excel資料裡面的表的名稱,後面一定要加 set rs conn2.execute sql while no...
Excel資料匯入到oracle
excel資料匯入到oracle 第一步 將要匯入的excel檔案開啟,選擇 另存為 在檔案型別那裡選擇 文字.txt 後確定儲存 第二步 開啟記事本,編寫下列的內容 注釋 1 控制檔案標識 2 剛才由excel檔案轉化過來的檔案的路徑 3 向oracle的資料表t network agent ba...
Excel資料匯入到Access
下面是asp的全部程式,需要做的是建乙個test.mdb資料庫和乙個test.xls的excel 查詢excel準備匯入到access sql select from sheet1 要匯入的excel資料裡面的表的名稱,後面一定要加 set rs conn2.execute sql while no...