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

推荐订阅源

人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
小众软件
小众软件
有赞技术团队
有赞技术团队
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
J
Java Code Geeks
罗磊的独立博客
V
Visual Studio Blog
雷峰网
雷峰网
H
Help Net Security
T
The Blog of Author Tim Ferriss
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
F
Fortinet All Blogs

博客园 - Leon0812

Export csv Export Excel Jquery pluign development example XML Mail Template Management Resource file management iframe 中显示内嵌页的局部 - Leon0812 - 博客园 easyslider - Leon0812 - 博客园 缩放页面字体 可编辑DIV - Leon0812 - 博客园 vs快捷键大全(转) SQL文件執行 利用IHttpModule、IHttpHandler做授权类 - Leon0812 - 博客园 C#调用非托管的DLL 无缝滚动 - Leon0812 - 博客园 获取-编译-打包 VS作业一条龙批处理 Reporting Service for SQL 2008匿名访问报表方法 獲取控件位置 - Leon0812 - 博客园 Installscript中修改web.config - Leon0812 - 博客园 publish
Excel Reader
Leon0812 · 2011-08-31 · via 博客园 - Leon0812
       string excelFile = Server.MapPath("~/service/data.xlsx");//string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + excelFile + ";Extended Properties=Excel 8.0;";
string strConn = @"Provider=Microsoft.Ace.OleDb.12.0;Data Source= " + excelFile + ";Extended Properties='Excel 12.0;HDR=No;IMEX=1'";
OleDbDataReader myDataReader
= null;
OleDbConnection myOleDbConnection
= new OleDbConnection(strConn);
OleDbCommand myOleDbCommand
= new OleDbCommand("SELECT * FROM [table1$]", myOleDbConnection);
myOleDbConnection.Open();
myDataReader
= myOleDbCommand.ExecuteReader();
try
{

ModeBiz biz

= new ModeBiz();
Mode model
= new Mode();
string name = string.Empty;
while (myDataReader.Read())
{
model
= new Mode();
name
= myDataReader.GetValue(4).ToString();

biz.Add(model);
}
}

#region Catch
catch (System.Threading.ThreadAbortException ex)
{
ViewBag.ErrMsg
= ex.Message;
}
catch (Exception ex)
{
ViewBag.ErrMsg
= ex.Message;
}
finally
{
myDataReader.Close();
myOleDbConnection.Close();
}
#endregion