初步认识asp.net中导入excell
来源:互联网 发布:在淘宝买到假货怎么办 编辑:程序博客网 时间:2024/05/22 07:51
2012年12月8日。初次接触把excell中的数据导入数据库,做个笔记吧。以备忘了只需。
protected void btnRead_Click(object sender, EventArgs e)
{
if (this .fulChoose .HasFile )//如果fileupload控件里面有文件
{
string fileExtension = System.IO.Path.GetExtension(this .fulChoose .PostedFile .FileName );//获得文件的扩展名
if (fileExtension .ToLower ()==".xls")
{
string serverPath = Server.MapPath("UploadExcells");
if (!System .IO .Directory .Exists (serverPath ))
{
System.IO.Directory.CreateDirectory(serverPath);
}
string newPath = serverPath + "\\" + this.fulChoose.FileName;
this.fulChoose.SaveAs(newPath );//保存该文件
DataSet ds = new DataSet();
OleDbConnection con = new OleDbConnection(string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"Excel 8.0;\";Data Source={0};", newPath ));
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [xixi$A:T]", con);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
cb.QuotePrefix = "[";
cb.QuoteSuffix = "]";
try
{
con.Open();
da.Fill(ds, 0, 0, "[heihei$]");
}
catch (Exception)
{
throw;
}
finally { con.Close(); }
if (ds.Tables [0]!=null )
{
for (int i = 0; i < ds.Tables [0].Rows .Count ; i++)
{
DataRow r = ds.Tables[0].Rows[i];
string m = r[0].ToString();
}
}
}
else
{
this.ClientScript.RegisterStartupScript(Page.GetType(), "hello", "<script>alert('请选择.xls格式的文件!');</script>");
}
}
else
{
this.ClientScript.RegisterStartupScript(Page.GetType(), "hello", "<script>alert('请选择要阅读的文件');</script>");
}
}
}
- 初步认识asp.net中导入excell
- ASP.NET C# Excell导入导出
- 【ASP.net】基础知识的初步认识
- 把DBGridEh导入到Excell中
- asp.net控件开发基础(7) ----------初步认识复合控件
- ASP.NET底层的初步认识与理解
- ASP.NET底层的初步认识与理解
- ASP.NET底层的初步认识与理解
- SQL 导入Excell问题
- Ajax 导入excell 备用
- ASP.NET 中数据库操作初步
- ASP.NET 中数据库操作初步
- asp.net 中数据库操作初步
- ASP.NET中数据库操作初步
- ASP.NET初步学习
- 【ASP.NET】初步了解
- ASP.net初步了解
- Asp.net中Excel文件导入sqlServer
- c# wince 文本操作
- java 实现关机工具,托盘图标
- stosb指令解析
- 产后复原:预防胸/部下垂
- 高德地图-绘制个人历史位置路线
- 初步认识asp.net中导入excell
- loadsb指令解析
- checkstyle插件问题总结
- 导入项目出现Project has no default.properties file错误总结
- Struts2框架验证--短路较验(short-circuit)
- 关于CSDN的一些看法
- GetMyName_newInstance
- C++中指针和引用的区别
- 杨辉三角