未能找到路径“F:\批量导入\upfiles\20100825024205新建 Microsoft Excel 工作表.xls”的一部分
ASP.NET想把excel导入到SQL数据库,在excel保存到服务器这一部出问题了,是在本机上测试的。后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string strConn = "server=.;user id=sa;pwd=;DataBase=master"; //链接SQL数据库
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(strConn);
cn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from hhaspx_gz", cn);
DataSet ds = new DataSet();
sda.Fill(ds, "hhaspx_gz");
this.GridView1.DataSource = ds.Tables["hhaspx_gz"];
this.GridView1.DataKeyNames = new string[] { "hhaspx_id" };
this.GridView1.DataBind();
}
/**/
/// <summary>
/// 查询EXCEL电子表格添加到DATASET
/// </summary>
/// <param name="filenameurl">服务器路径</param>
/// <param name="table">表名</param>
///
/// <returns>更多内容请访问:www.hhaspx.com</returns>
/// 红河ASP.NET(C#)学习网包含ASP.NET 教程,c#教程,Photoshop,ps教程,网页制作,图片素材,SEO优化
public DataSet ExecleDs(string filenameurl, string table)
{
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filenameurl + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter odda = new OleDbDataAdapter("select * from [Sheet1$]", conn);
odda.Fill(ds, table);
return ds;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile == false)//HasFile用来检查FileUpload是否有指定文件
{
Response.Write("<script>alert('请您选择Excel文件')<