最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 读取Excel数据,填充DataSet 与GridView代码
时间:2022-06-25 05:06:56 编辑:袖梨 来源:一聚教程网
asp教程.net 读取excel数据,填充dataset 与gridview代码
// 连接字符串
string ph = string.format("upload{0}", name);
string xlspath = server.mappath(ph);
string connstr = "provider=microsoft.jet.oledb.4.0;" + "extended properties="excel 8.0;hdr=no;imex=1";" + "data source=" + xlspath;
string sql_f = "select * from [{0}]";oledbconnection conn = null;
oledbdataadapter da = null;
datatable tblschema = null;
ilisttblnames = null; // 初始化连接,并打开
conn = new oledbconnection(connstr);
conn.open();
//方法二
连接字符串
dim xlspath as string = server.mappath("~/app_data/excelfile.xls") ' 绝对物理路径
dim connstr as string = "provider=microsoft.jet.oledb.4.0;data source=" & xlspath & "; extended properties=excel 8.0;"
' 查询语句
dim sql as string = "select * from [sheet1$]"dim ds as dataset = new dataset()
dim da as oledb.oledbdataadapter = new oledb.oledbdataadapter(sql, connstr)
da.fill(ds) ' 填充dataset' 在这里对dataset中的数据进行操作
' 输出,绑定数据
gridview1.datasource = ds.tables(0)
gridview1.databind()
上面代码是讲了绑定到gridview中的代码
相关文章
- 豆包AI智能在线网页解析神器-豆包AI智能在线会议纪要生成助手 12-14
- 小红书Web官网登录入口-小红书官方网页版一键登录 12-14
- 苍云阅读app如何快速找到目录-目录入口位置 12-14
- 苹果ID登录官网入口 - 苹果Apple ID账户登录页面一键直达 12-14
- 苍云阅读app如何快速打开目录-目录入口详解 12-14
- 漫蛙漫画网页版入口-漫蛙漫画官网APP免费下载直达 12-14