Microsoft Office Access数据库引擎找不到对象'Sheet1 $' [英] The Microsoft Office Access database engine could not find the object 'Sheet1$'

查看:157
本文介绍了Microsoft Office Access数据库引擎找不到对象'Sheet1 $'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我!!这是紧急的



这是我的代码没有任何错误但我得到错误为什么?

Please help me!! It is urgent

This is my code There is not any mistake But I get error Why?

string path = Server.MapPath(FileUpload1.FileName).ToString();
string str3 = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0; Xml; HDR=YES\"";
OleDbConnection excelcon = new OleDbConnection(str3);
excelcon.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [Sheet1$]", excelcon);
            DataSet myDataSet = new DataSet();
            myCommand.Fill(myDataSet);
            excelcon.Close();





我的Excel文件工作表名称也是Sheet1

推荐答案

,excelcon);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet);
excelcon.Close();
", excelcon); DataSet myDataSet = new DataSet(); myCommand.Fill(myDataSet); excelcon.Close();





我的excel文件工作表名称也是Sheet1


尝试使用下面给出的代码。这是一个有效的代码。在代码中,连接字符串的声明方式略有变化 - < br $> b $ b

Try using the code given below. It's a working code. In the code there is a slight change in the way connection string is declared--

Protected Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click
    Try

        If updFile.HasFile = True Then
            Dim ExcelConn As String
            Dim fileExtension As String = Path.GetExtension(updFile.FileName)
            Dim fileName As String = Server.MapPath("~/Admin/Payroll/upload/") & Date.Now.Hour & Date.Now.Minute & Date.Now.Second & Date.Now.Millisecond & fileExtension

            If fileExtension <> ".xls" And fileExtension <> ".xlsx" Then
                tdError.InnerText = "Select Valid Excel File"
                Exit Sub
            End If

            updFile.SaveAs(fileName)

            If fileExtension = ".xls" Then
                ExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fileName & ";Extended Properties='Excel 8.0;HDR=YES;'"
            Else
                ExcelConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & fileName & ";Extended Properties='Excel 12.0 Xml;HDR=YES;'"
            End If


            Dim dtFill As New DataTable

            Using oleDBConn As New OleDbConnection(ExcelConn)
                Dim daFill As New OleDbDataAdapter("Select * from [Attendance


,ExcelConn中选择*
daFill.Fill(dtFill)
AttendanceImport.ImportAttendance(dtFill,Session( AdminID))
结束 使用

tdError.InnerText = 出勤表成功上传
Else
tdError.InnerText = No file Selected
退出 Sub
End 如果
Catch ex As 异常
tdError.InnerText = ex.Message
结束 尝试
结束 Sub
", ExcelConn) daFill.Fill(dtFill) AttendanceImport.ImportAttendance(dtFill, Session("AdminID")) End Using tdError.InnerText = "Attendance Sheet Uploaded Successfully" Else tdError.InnerText = "No file Selected" Exit Sub End If Catch ex As Exception tdError.InnerText = ex.Message End Try End Sub


这篇关于Microsoft Office Access数据库引擎找不到对象'Sheet1 $'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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