错误:Microsoft Jet数据库引擎找不到对象'ExportData $'。确保对象存在,并且您正确拼写其名称和路径名称。 [英] Error:The Microsoft Jet database engine could not find the object 'ExportData$'. Make sure the object exists and that you spell its name and the path name correctly.

查看:87
本文介绍了错误:Microsoft Jet数据库引擎找不到对象'ExportData $'。确保对象存在,并且您正确拼写其名称和路径名称。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我正在使用vs2010和c#asp.net我想阅读Excel文件。我正在使用以下代码,但我收到错误消息( 错误:Microsoft Jet数据库引擎无法找到对象'ExportData $'。请确保该对象存在,并且您正确拼写其名称和路径名。)。任何人都可以帮我解决问题。



  string  strFileType = Path.GetExtension(FileUpload1.FileName).ToLower(); 
string path = FileUpload1.PostedFile.FileName;
// Excel工作簿的连接字符串
if (strFileType.Trim()== 。xls
{
connString = Provider = Microsoft.Jet.OLEDB.4.0; Data Source = + path + ;扩展属性= \Excel 8.0; HDR =是; IMEX = 2 \ ;
}
else if (strFileType.Trim()== 。xlsx
{
connString = Provider = Microsoft.ACE.OLEDB.12.0; Data Source = + path + ;扩展属性= \Excel 12.0; HDR =是; IMEX = 2 \;
}
string query = SELECT [UserName],[Education],[Location] FROM [ExportData $];
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbCommand cmd = new OleDbCommand(query,conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);







感谢Advance!..

解决方案

'。确保对象存在,并正确拼写其名称和路径名。)。任何人都可以帮我解决问题。



  string  strFileType = Path.GetExtension(FileUpload1.FileName).ToLower(); 
string path = FileUpload1.PostedFile.FileName;
// Excel工作簿的连接字符串
if (strFileType.Trim()== .xls
{
connString = Provider = Microsoft。 Jet.OLEDB.4.0;数据源= +路径+ ;扩展属性= \Excel 8.0; HDR =是; IMEX = 2 \;
}
其他 if (strFileType.Trim()== 。xlsx
{
connString = Provider = Microsoft.ACE.OLEDB.12.0 ;数据源= +路径+ ;扩展属性= \Excel 12.0; HDR =是; IMEX = 2\ ;
}
string query = SELECT [UserName],[Education],[Location] FROM [ExportData


;
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbCommand cmd = new OleDbCommand(query,conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);







感谢Advance!..


您可以使用以下代码检查Excel文件中工作表的名称:

 DataTable schemaTable = dbConnection.GetOleDbSchemaTable(OleDbSchemaGuid) .Tables, new   object  [] { null }); 

foreach (DataRow dataRow in schemaTable.Rows)
{
string tableName = dataRow [ TABLE_NAME ]的ToString(); // 从每个架构条目中获取工作表名称
if (!tableName.EndsWith( _))
{
// 一些显示名称的代码
}
}


Dear All,

I am using vs2010 and c# asp.net i want to read Excel File.I am using following code but i get the Error Message("Error :The Microsoft Jet database engine could not find the object 'ExportData$'. Make sure the object exists and that you spell its name and the path name correctly."). any one help me how to solve the problem.

string strFileType = Path.GetExtension(FileUpload1.FileName).ToLower();
        string path = FileUpload1.PostedFile.FileName;
        //Connection String to Excel Workbook
        if (strFileType.Trim() == ".xls")
        {
            connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
        }
        else if (strFileType.Trim() == ".xlsx")
        {
            connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
        }
        string query = "SELECT [UserName],[Education],[Location] FROM [ExportData$]";
        OleDbConnection conn = new OleDbConnection(connString);
        if (conn.State == ConnectionState.Closed)
            conn.Open();
        OleDbCommand cmd = new OleDbCommand(query, conn);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);




thanks Advance!..

解决方案

'. Make sure the object exists and that you spell its name and the path name correctly."). any one help me how to solve the problem.

string strFileType = Path.GetExtension(FileUpload1.FileName).ToLower();
        string path = FileUpload1.PostedFile.FileName;
        //Connection String to Excel Workbook
        if (strFileType.Trim() == ".xls")
        {
            connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
        }
        else if (strFileType.Trim() == ".xlsx")
        {
            connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
        }
        string query = "SELECT [UserName],[Education],[Location] FROM [ExportData


"; OleDbConnection conn = new OleDbConnection(connString); if (conn.State == ConnectionState.Closed) conn.Open(); OleDbCommand cmd = new OleDbCommand(query, conn); OleDbDataAdapter da = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds);




thanks Advance!..


You can use the following code to check the names of the sheets in the Excel file:

DataTable schemaTable = dbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null });
    
foreach (DataRow dataRow in schemaTable.Rows)
{
    string tableName = dataRow["TABLE_NAME"].ToString();	// gets the sheet name from each schema entry
    if (!tableName.EndsWith("_"))
    {
        // some code to display the name
    }
}


这篇关于错误:Microsoft Jet数据库引擎找不到对象'ExportData $'。确保对象存在,并且您正确拼写其名称和路径名称。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆