我已經搜遍了網絡,發現很多人問這個問題,但沒有人確定我的答案。System.Data.OleDb.OleDbException:無法找到可安裝的ISAM
我有一個連接類和一個在頁面中使用該類的方法。
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:找不到可安裝的ISAM。
任何人都可以請幫忙嗎?
在這個問題右邊的相關欄目中,您會發現幾十個與您的問題相同的問題。 – Steve 2012-07-19 13:53:28