【发布时间】:2012-05-29 19:15:51
【问题描述】:
根据我的要求,我成功地从 Asp.net OLEDB 打开和读取 Excel(2003 年和 07 年)数据。
但它只有在我们的 PC 中保持打开 Excel 表时才有效,否则它会给出“外部表格格式错误”。究竟是什么问题?。谁能告诉我。 访问权限有什么问题吗?
我确定它与连接字符串无关。我的代码
protected void Page_Load(object sender, EventArgs e)
{
string path = @"C:\Users\abcd\Desktop\raj.xls";
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + absoluteDir + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
OleDbConnection oledbConn = new OleDbConnection(connStr);
try
{
oledbConn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
DataSet ds = new DataSet();
oleda.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
catch (Exception err)
{
}
finally
{
// Close connection
oledbConn.Close();
}
}
提前致谢
【问题讨论】:
标签: asp.net asp.net-mvc excel oledb