日期:2014-05-18  浏览次数:20572 次

Microsoft Jet 数据库引擎找不到对象'Sheet1$'。请确定对象是否存在,并正确地写出它的名称和路径。
string strConn = @"Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source ='" + inputExcel.Value + "' ;Extended Properties=Excel 8.0";
  string strselect = " select * from [Sheet1$] ";
  OleDbConnection Connection = new OleDbConnection(strConn);
  Connection.Open();
  OleDbDataAdapter da = new OleDbDataAdapter(strselect, Connection);
  DataSet ds = new DataSet();
  da.Fill(ds);
  GridView1.DataSource = ds.Tables[0];
  GridView1.DataBind();
  Connection.Close();

这代码,运行在别人电脑上可以,自己的就报错:Microsoft Jet 数据库引擎找不到对象'Sheet1$'。请确定对象是否存在,并正确地写出它的名称和路径。

------解决方案--------------------
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
String fileName = System.IO.Path.GetFileName(FileUpload1.FileName);
String path = Server.MapPath("~/" + fileName);
FileUpload1.SaveAs(path);
string strConn = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0'";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
  
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="upload" />
  
</form>
</body>
</html>