未处理的异常从任何Excel读取数据

时间:2012-02-26 09:28:18

标签: c# excel

如何解决此错误

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

其他信息:Microsoft Jet数据库引擎找不到对象Sheet1。确保对象存在,并正确拼写其名称和路径名“

关于此代码

using System.Data.OleDb;
 String sConnectionString ="Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=      Book1;" + "Extended Properties=Excel 8.0;";


        OleDbConnection objConn = new OleDbConnection(sConnectionString);
        objConn.Open();
        OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1]",objConn);
        OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
        objAdapter1.SelectCommand = objCmdSelect;
        DataSet objDataset1 = new DataSet();
        objAdapter1.Fill(objDataset1);
        objConn.Close(); 

1 个答案:

答案 0 :(得分:1)

尝试使用[Sheet1 $]代替[Sheet1]。