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"))
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