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

前端之家收集整理的这篇文章主要介绍了asp.net – System.Data.OleDb.OleDbException:找不到可安装的ISAM前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在网上搜索过,发现很多人都在问这个问题,但没有人能解决我的问题.

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

DataConn.cs

  1. public static OleDbConnection ConnectExcel()
  2. {
  3. //Store the connection details as a string
  4. string connstr =
  5. String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pricelist.xlsx;Extended Properties=Excel 12.0 Xml;HDR=YES");
  6.  
  7. //Initialise the connection to the server using the connection string.
  8. OleDbConnection oledbConn = new OleDbConnection(connstr);
  9.  
  10. //Open the connection,we do this here so we can instantly be able to use sql commands in the code.
  11. oledbConn.Open();
  12.  
  13. return oledbConn;
  14. }
  15.  
  16. public static void DisconnectExcel()
  17. {
  18. _oledbConn.Dispose();
  19. _oledbConn.Close();
  20. }

以及调用它的代码

  1. protected void Page_Load(object sender,EventArgs e)
  2. {
  3. // Connection String
  4. const string xlStr = "SELECT * FROM [Sheet2$]";
  5.  
  6. // Create OleDbCommand object and select data from worksheet Food
  7. OleDbCommand cmd = new OleDbCommand(xlStr,DataConn.ConnectExcel());
  8.  
  9. // Create new OleDbDataAdapter
  10. OleDbDataAdapter oleda = new OleDbDataAdapter();
  11.  
  12. oleda.SelectCommand = cmd;
  13.  
  14. // Create a DataSet which will hold the data extracted from the worksheet.
  15. DataSet ds = new DataSet();
  16.  
  17. // Fill the DataSet from the data extracted from the worksheet.
  18. oleda.Fill(ds);
  19.  
  20. // Bind the data to the GridView
  21. gridPricelist.DataSource = ds;
  22. gridPricelist.DataBind();
  23. }

是的我仍然得到:

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

有人可以帮忙吗?

解决方法

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

修改你的连接字符串

  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

猜你在找的asp.Net相关文章