zoukankan
html css js c++ java
个人学习代码保存:例11.读取Excel文件中的数据
前台代码:Default.aspx
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
无标题页
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
<
asp:GridView
ID
="GridView1"
runat
="server"
>
</
asp:GridView
>
</
div
>
</
form
>
</
body
>
</
html
>
后台代码:Default.aspx.cs
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Data.OleDb;
public
partial
class
_Default : System.Web.UI.Page
{
private
static
string
connstr
=
ConfigurationManager.AppSettings[
"
ConnectionString
"
].ToString();
private
static
string
dbpath
=
ConfigurationManager.AppSettings[
"
DBPATH
"
].ToString();
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{
this
.GridView1.DataSource
=
CreateDataSource();
this
.GridView1.DataBind();
}
}
private
DataSet CreateDataSource()
{
String ExcelDBPath
=
connstr
+
Server.MapPath(dbpath)
+
"
;
"
;
OleDbConnection conn
=
new
OleDbConnection(ExcelDBPath);
OleDbDataAdapter myCommand
=
new
OleDbDataAdapter(
"
SELECT * FROM [Sheet1$]
"
, conn);
DataSet myDataSet
=
new
DataSet();
myCommand.Fill(myDataSet);
return
myDataSet;
}
}
web.config
<?
xml version="1.0"
?>
<
configuration
xmlns
="http://schemas.microsoft.com/.NetConfiguration/v2.0"
>
<
appSettings
>
<
add
key
="ConnectionString"
value
="Provider=Microsoft.Jet.OLEDB.4.0; Extended Properties=Excel 8.0;Data Source="
/>
<
add
key
="DBPATH"
value
="ExcelDB\username.xls"
></
add
>
</
appSettings
>
<
system.web
>
<
compilation
debug
="true"
/></
system.web
></
configuration
>
查看全文
相关阅读:
Python学习笔记(尚硅谷)——变量
四级高频词-工作类
转载--JS根据浏览器的useAgent来判断浏览器的类型
MySQL上传文件容量过大com.mysql.jdbc.PacketTooBigException
关于<input type="file" >浏览器兼容问题
IDictionary与TryGetValue
生成自增ID列
利用C#将PCM格式的Wav进行对文件裁剪截取、淡入淡出、保存为音频文件相关详细代码解释
DevExpress控件学习总结
C# 音频操作系统项目总结
原文地址:https://www.cnblogs.com/wbcms/p/1037568.html
最新文章
JVM
Mybatis SqlsessionFactory
Mybatis 接口代理的实现(BeanDefinitionRegistryPostProcessor+FactoryBean)
jdk1.8 HashMap的实现
Spring基础-BeanPostProcessor
Spring基础-如何获取ApplicationContext
Spring基础
http升级为https
Redis zset
redis set操作
热门文章
Redis list 操作
redis hash操作
redis 字符串基本操作
LeetCode-返回倒数第 k 个节点
概率论-随机事件及其概率
HTML表单input里面的value的作用
JavaWeb项目中解决中文乱码方法
MATLAB基础知识
Mysql基础笔记
try-catch-finally机制
Copyright © 2011-2022 走看看