文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > aspnet实现将Excel中的数据导入数据库
侵权投诉

aspnet实现将Excel中的数据导入数据库

.net实现将Excel中的数据导入数据库
Posted on 2009-12-23 16:32 飛雪飄寒 阅读(7661) 评论(33) 编辑 收藏
  在近期的项目中需要实现将Excel中的数据导入到数据库的功能,相信各位博友也会经常有这样的需求,现把我的实现方式与大家分享一下,如果哪位博友有更好的实现方式,欢迎补充!
  实现思路:先上传Excel文件,然后用OleDB连接Excel文件,将Excel数据导入Dataset,再将Dataset数据导入数据库,最后再将上传的Excel文件删除。
  前台代码:  
<table class="Text" cellSpacing="1" cellPadding="0" width="100%" bgColor="#1d82d0" border="0">
<tr bgColor="#ffffff">
<td vAlign="top">
<table class="Text" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td width="15">&nbsp;</td>
<td vAlign="top" width="100%">
<table class="Text" cellSpacing="1" cellPadding="0" width="100%" border="0">
<tr height="30">
<td style="WIDTH: 120px" width="120"><FONT face="宋体">请选择要导入的文件</FONT></td>
<td style="WIDTH: 350px" align="left" width="350"><INPUT id="FileExcel" style="WIDTH: 300px" type="file" size="42" name="FilePhoto" runat="server"><FONT color="red"></FONT></td>
<td class="hint"><FONT face="宋体"><asp:button id="BtnImport" Text="导 入" CssClass="button" Runat="server"></asp:button></FONT></td>
</tr>
</table>
</td>
</tr>
</table>
<asp:label id="LblMessage" runat="server" Font-Bold="True" ForeColor="Red"></asp:label>
</td>
</tr>
</table>
复制代码


  后台代码:
  
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Text;

namespace GZPI.Service.AgenciesChannel
{
/// <summary>
/// ImportXlsToData 的摘要说明。
/// </summary>
public class ImportXlsToDataBase : GZPI.Service.AgenciesChannel.AgenciesBasePage
{
protected System.Web.UI.HtmlControls.HtmlInputFile FileExcel;
protected System.Web.UI.WebControls.Button BtnImport;
protected System.Web.UI.WebControls.Label LblMessage;
protected ZsoftDataAccess.DataAccess _da = new ZsoftDataAccess.DataAccess();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

第1页

你可能喜欢

  • excel汇总
  • 数据库导入
  • 读取文件
  • excel数据
  • C#数据库
  • Excel数据库
  • ASP.NET开发大全

热门文档

相关文档

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email