.net实现上传excel到服务器,并读取到数据库
首先配置web.config文件,方便后面的连接
<appSettings>
<add key="设置连接名称" value="data source=数据库服务器地址;initial catalog=数据库名;UID=用户名;PWD=密码;Pooling=true;Connect Timeout=120"/>
</appSettings>
前端:
<asp:FileUpload ID="fuOpen" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="上传" onclick="btnUpload_Click" />
后台:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls