Microsoft Access数据库引擎找不到对象'Sheet1 $'。 [英] The Microsoft Access database engine could not find the object 'Sheet1$'.
本文介绍了Microsoft Access数据库引擎找不到对象'Sheet1 $'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用数据集将Excel工作表数据加载到网格中。但我收到此错误Microsoft Access数据库引擎无法找到对象'Sheet1 $'。
以下是代码。谁能告诉我告诉我哪里做错了。我试图加载的excel表已经有Sheet1。连接字符串也是正确的。
oledbConn.Open()
Dim comm As OleDbCommand = New OleDbCommand(Select * from [Sheet1 $],oledbConn)
Dim oleda As新OleDbDataAdapter(comm)
oleda.SelectCommand()= comm
Dim ds As New DataSet()
oleda.Fill(ds)
gdExcel.DataSource = ds.Tables(0).DefaultView
gdExcel.DataBind()
Catch ex As Exception
MsgBox(error,vbInformation)
最后
oledbConn.Close()
解决方案
'。
<下面是
代码。任何人都可以告诉我告诉我在哪里做错了。我试图加载的excel表已经有了Sheet1。连接字符串也是正确的。
oledbConn.Open()
Dim comm As OleDbCommand = New OleDbCommand(Select * from [Sheet1
,ole dbConn)
Dim oleda As New OleDbDataAdapter(comm)
oleda.SelectCommand()= comm
Dim ds As New DataSet()
oleda.Fill(ds)
gdExcel.DataSource = ds.Tables(0).DefaultView
gdExcel.DataBind()
Catch ex As Exception
MsgBox(error,vbInformation)
最后
oledbConn.Close()
使用此代码希望你得到你的答案。
string strConn = @ Provider = Microsoft.ACE.OLEDB.12.0; Data Source = + filename + @ ;扩展属性=Excel 12.0 Xml; HDR = YES;
OleDbConnection myData = new OleDbConnection(strConn);
尝试
{
myData.Open();
}
catch (OleDbException ex)
{
}
int i = 0 ;
foreach (DataRow row in myData.GetSchema( tables)。行)
尝试
{
i ++;
string name = row [ 2 ]。ToString()。替换( '', ')。TrimEnd(' _');
DataSet ds = new DataSet();
OleDbDataAdapter d = new OleDbDataAdapter( SELECT *来自[ + name + ],strConn);
d.Fill(ds);
}
catch (例外情况)
{
}
Hi,
I am trying to load excel sheet data into grid using dataset. but I am getting this error "The Microsoft Access database engine could not find the object 'Sheet1$'."
below is the code. could anyone tell me tell where i am doing wrong. the excel sheet I am trying to load already has Sheet1. Also connection string is correct.
oledbConn.Open() Dim comm As OleDbCommand = New OleDbCommand("Select * from [Sheet1$]", oledbConn) Dim oleda As New OleDbDataAdapter(comm) oleda.SelectCommand() = comm Dim ds As New DataSet() oleda.Fill(ds) gdExcel.DataSource = ds.Tables(0).DefaultView gdExcel.DataBind() Catch ex As Exception MsgBox("error", vbInformation) Finally oledbConn.Close()
解决方案
'."
below is the code. could anyone tell me tell where i am doing wrong. the excel sheet I am trying to load already has Sheet1. Also connection string is correct.
oledbConn.Open() Dim comm As OleDbCommand = New OleDbCommand("Select * from [Sheet1
", oledbConn) Dim oleda As New OleDbDataAdapter(comm) oleda.SelectCommand() = comm Dim ds As New DataSet() oleda.Fill(ds) gdExcel.DataSource = ds.Tables(0).DefaultView gdExcel.DataBind() Catch ex As Exception MsgBox("error", vbInformation) Finally oledbConn.Close()
USE this code hope you got your ans.
string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + @";Extended Properties=""Excel 12.0 Xml;HDR=YES"""; OleDbConnection myData = new OleDbConnection(strConn); try { myData.Open(); } catch (OleDbException ex) { } int i = 0; foreach (DataRow row in myData.GetSchema("tables").Rows) try { i++; string name = row[2].ToString().Replace("''", "'").TrimEnd('_'); DataSet ds = new DataSet(); OleDbDataAdapter d = new OleDbDataAdapter("SELECT * from [" + name + "]", strConn); d.Fill(ds); } catch (Exception ex) { }
这篇关于Microsoft Access数据库引擎找不到对象'Sheet1 $'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文