asp.net – System.Data.OleDb.OleDbException:找不到可安装的ISAM

我在网上搜索过,发现很多人都在问这个问题,但没有人能解决我的问题.

我有一个Connection类,以及一个页面中使用该类的方法.

DataConn.cs

public static OleDbConnection ConnectExcel()
{
    //Store the connection details as a string
    string connstr =
        String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pricelist.xlsx;Extended Properties=Excel 12.0 Xml;HDR=YES");

    //Initialise the connection to the server using the connection string.
    OleDbConnection oledbConn = new OleDbConnection(connstr);

    //Open the connection,we do this here so we can instantly be able to use sql commands in the code.
    oledbConn.open();

    return oledbConn;
}

public static void disconnectExcel()
{
    _oledbConn.dispose();
    _oledbConn.Close();
}

以及调用它的代码

protected void Page_Load(object sender,EventArgs e)
{
    // Connection String
    const string xlStr = "SELECT * FROM [Sheet2$]";

    // Create OleDbCommand object and select data from worksheet Food
    OleDbCommand cmd = new OleDbCommand(xlStr,DataConn.ConnectExcel());

    // Create new OleDbDataAdapter
    OleDbDataAdapter oleda = new OleDbDataAdapter();

    oleda.SelectCommand = cmd;

    // Create a DataSet which will hold the data extracted from the worksheet.
    DataSet ds = new DataSet();

    // Fill the DataSet from the data extracted from the worksheet.
    oleda.Fill(ds);

    // Bind the data to the GridView
    gridPricelist.DataSource = ds;
    gridPricelist.DataBind();
}

是的我仍然得到:

System.Data.OleDb.OleDbException: Could not find installable ISAM.

有人可以帮忙吗?

解决方法

如果使用多于1个扩展属性,则必须引用值标记,否则驱动程序无法将它们与连接字符串中的其他非扩展属性区分开来;
...Extended Properties=""Excel 8.0;IMEX=1"""

修改你的连接字符串

String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pricelist.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES""");

参考:
Could not find installable ISAM

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...