这里我试图将excel表数据保存到数据集中。帮助我解决此错误 Microsoft Jet数据库引擎找不到对象'Sheet1 $'。确保对象存在,并且您正确拼写其名称和路径名称。 Dim ds As System.Data.DataSet Dim RecTab As Data.DataTable Dim RecTab1 As Data.DataTable Dim Rectab2 As Data.DataTable Dim ds1 As System.Data.DataSet Dim HFCell As String 昏暗的HTCell As String Dim FilePath As String
HFCell = "A1"
HTCell = "B1"
m_FileName = "Data.xls"
FilePath = Server.MapPath("..\TankGauge\Data_Mgr") & "\" & m_FileName
Try
Dim connectionString As String = ""
Try
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + FilePath + ";" + "Extended Properties=Excel 8.0;"
MyConnection = New OleDbConnection(connectionString)
MyConnection.Open()
dataAdapter = New OleDbDataAdapter("SELECT * FROM [Sheet1$]", MyConnection)
ds = New Data.DataSet
dataAdapter.Fill(ds)
RecTab = ds.Tables(0)
MyConnection.Close()
答案 0 :(得分:0)
在Excel工作簿中,是否有名为Sheet1的工作表?如果没有,请重命名工作表或更改代码以调出要从中获取数据的工作表。
答案 1 :(得分:0)
我相信您使用的数据库驱动程序无法正常工作。尝试更改:
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + FilePath + ";" + "Extended Properties=Excel 8.0;"
为:
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + FilePath + ";" + "Extended Properties=Excel 8.0;"