惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
T
The Exploit Database - CXSecurity.com
V
Vulnerabilities – Threatpost
Know Your Adversary
Know Your Adversary
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Secure Thoughts
G
GRAHAM CLULEY
Google Online Security Blog
Google Online Security Blog
Help Net Security
Help Net Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
O
OpenAI News
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 最新话题
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Stack Overflow Blog
Stack Overflow Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
H
Hacker News: Front Page
W
WeLiveSecurity
P
Privacy International News Feed
Forbes - Security
Forbes - Security
月光博客
月光博客
PCI Perspectives
PCI Perspectives
T
Tailwind CSS Blog
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
Engineering at Meta
Engineering at Meta
F
Full Disclosure
AI
AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Visual Studio Blog
The Hacker News
The Hacker News
博客园 - 叶小钗
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss

博客园 - 一滴水

PHP基础学习(1)-Win2003下安装配置PHP 在右键菜单中添加 Dos cmd窗体,方便使用(意译) HTML转义字符表[zz] - 一滴水 - 博客园 SQLServer2000发生错误1069(由于登陆失败而无法启动服务)的解决方案[zz] - 一滴水 - 博客园 [转载]Javascript的IE和Firefox兼容性汇编 - 一滴水 - 博客园 Hibernate+mysql 乱码问题。。。 关于eclipse中cvs标记的[csdn] [Hibernate]在用hibernate3.0进行查询时,java.lang.NoClassDefFoundError: antlr/ANTLRException【问题记录】 js 文件的编码问题!! 【解决了】 我遇到的一些问题【解决了贴出来当积累了】 获得插入记录标识号的示例 如何得到服务器端数据库列表 并 备份和恢复数据库 [copy] 将 XML 文件做为数据源绑定到控件 单值数据绑定示例 网上整理 Web JS 通用 呵呵[还会陆续添加] 如何在DataGrid控件中删除最后一页的最后一记录 !!! 鼠标移到DataGrid的那行则更改那行的颜色!!! DataGrid中添加自动编号 关于使用docuemnt.write问题
读取Excel表格中的数据[copy]
一滴水 · 2005-04-09 · via 博客园 - 一滴水

Posted on 2005-04-09 03:46  一滴水  阅读(2879)  评论(3)    收藏  举报

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.OleDb" %>
<HTML>
    
<HEAD>
        
<title>如何读取Excel表格中的数据</title>
        
<script language="C#" runat="server">
        
            
void SubmitBtn_Click(object sender, System.EventArgs e)
            
{    
                
// 获取Excep文件的完整路径
                string source = File1.Value;
                string ConnStr 
= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + source + ";Extended Properties=Excel 8.0";
                string query 
= "SELECT * FROM [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();
            }

        
        
</script>
    
</HEAD>
    
<body>
        
<form id="Form1" method="post" runat="server">
            
<H3>如何读取Excel表格中的数据</H3>
            请选择Excel表格:
<BR>
            
<INPUT type="file" id="File1" name="File1" runat="server" size="26"><br>
            
<asp:Button 
                
id="SubmitBtn" 
                runat
="server" 
                Text
="开始显示" 
                OnClick
="SubmitBtn_Click">
            
</asp:Button><br>
            
<br>
            
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
        
</form>
    
</body>
</HTML>