日期:2014-05-17  浏览次数:20440 次

Excel 导人出现问题
Microsoft Office Access 数据库引擎找不到对象“C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\新建 Microsoft Excel 工作表.xlsx”。请确定该对象存在,并正确拼写其名称和路径名。



using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
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.Sql;
using System.Reflection;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    /**/
    /// <summary>
    /// 实现excel中的数据导入sql数据库中
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (File1.Value == string.Empty || File1.Value == "")
        {
            Response.Write("<Script>alert('选择路径');</Script>");
        }
        else
        {
            FileInfo file = new FileInfo(File1.PostedFile.FileName.ToString());
            string sConnectionString;
            string extension = file.Extension;
            switch (extension)
            {
                case ".xls":
                    sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
                    break;
                case ".xlsx":
                    sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + file + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
                    break;
                default:
                 &n