国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

asp.net C#取Excel 合并單元格內容

2019-11-17 01:51:02
字體:
來源:轉載
供稿:網友

asp.net C#取Excel 合并單元格內容

asp教程.net c#取excel 合并單元格內容讀取excel數據,填充dataset// 連接字符串 string xlspath = server.mappath("~/www.111cn.net/somefile.xls");string connstr = "

oledbconnection conn = null;oledbdataadapter da = null;datatable tblschema = null;ilist<string> tblnames = null;

// 初始化連接,并打開conn = new oledbconnection(connstr);conn.open();

// 獲取數據源的表定義元數據 //tblschema = conn.getschema("tables");tblschema = conn.getoledbschematable(oledbschemaguid.tables, new object[] { null, null, null, "table" });

//gridview1.datasource = tblschema;//gridview1.databind();

// 關閉連接//conn.close();

tblnames = new list<string>();foreach (datarow row in tblschema.rows) {tblnames.add((string)row["table_name"]); // 讀取表名}

// 初始化適配器da = new oledbdataadapter();// 準備數據,導入datasetdataset ds = new dataset();

foreach (string tblname in tblnames) {da.selectcommand = new oledbcommand(string.format(sql_f, tblname), conn);try {da.fill(ds, tblname);}catch {// 關閉連接if (conn.state == connectionstate.open) {conn.close();}throw;}}

// 關閉連接(www.111cn.net)if (conn.state == connectionstate.open) {conn.close();}

// 對導入dataset的每張sheet進行處理 // 這里僅做顯示gridview1.datasource = ds.tables[0];gridview1.databind();

gridview2.datasource = ds.tables[1];gridview2.databind();

// more codes// .這里我們就不需要對selec 語句進行"硬編碼",可以根據需要動態的構造from 字句的"表名"。

不僅可以,獲取表明,還可以獲取每張表內的字段名、字段類型等信息:tblschema = conn.getoledbschematable(oledbschemaguid.columns, new object[] { null, null, null, null });在ado.net 1.x 時候只有oledb提供了getoledbschematable 方法,而sqlclient或者orcaleclient沒有對應的方法,因為對應數據庫教程已經提供了類似功能的存儲過程或者系統表供應用程序訪問,比如對于sql server: select *from northwind.information_schema.columnswhere table_name = n'customers'

而在ado.net 2.0中每個xxxconnenction都實現了基類system.data.common.dbconnection的 getschemal

private dataset binddsfromexcel(string strfiledir, string strdataname){string strconn;strconn = "provider=microsoft.jet.oledb.4.0;data source=" + strfiledir + ";extended properties='excel 8.0;hdr=false;imex=1'";oledbconnection oleconn = new oledbconnection(strconn);oleconn.open();string sql = "select * from [" + strdataname + "$]";//如果不知道名字就用sheets[1]

oledbdataadapter oledaexcel = new oledbdataadapter(sql, oleconn);dataset oledsexcle = new dataset();oledaexcel.fill(oledsexcle, strdataname);oleconn.close();return oledsexcle;}from:http://www.111cn.net/net/net/35137.htm


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 城步| 天柱县| 新津县| 安庆市| 清水县| 黄平县| 吉木萨尔县| 将乐县| 报价| 驻马店市| 苗栗市| 喀喇沁旗| 东乡| 汝城县| 都江堰市| 若尔盖县| 赤峰市| 双流县| 和林格尔县| 高雄县| 安徽省| 咸阳市| 商河县| 东乡族自治县| 丽江市| 三门县| 巴彦淖尔市| 洛川县| 金昌市| 丰顺县| 弥渡县| 沙田区| 万州区| 通化市| 朝阳县| 宿州市| 昭平县| 油尖旺区| 富阳市| 钟祥市| 商河县|