本文介绍了System.Data.OleDb.OleDbException:找不到可安装ISAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经走遍了网,发现很多人都在问这个,但都没有固定我的答案。
I have scoured the net, and found many people asking this, yet none have fixed my answer.
我有一个连接类,以及使用该类在一个页面的方法。
I have a Connection Class, and a Method that uses that Class in a page.
DataConn.cs
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();
}
而code调用它
And the code that calls it
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();
}
是的,我仍然得到:
Yes I STILL get:
的 System.Data.OleDb.OleDbException:找不到可安装ISAM 的
任何人都可以请帮助?
推荐答案
如果您使用超过1扩展属性则该值标记必须用引号引起来,否则就没有办法为驾驶者从其他非扩展区分开来在连接字符串中的属性;
If you use more than 1 extended property then the value tokens must be quoted, otherwise there is no way for the driver to distinguish them from the other non-extended properties in the connection string;
...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""");
参考:
这篇关于System.Data.OleDb.OleDbException:找不到可安装ISAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!