Hi jasminkp
You can use this function to get records form excel it is tested and working.
Public Shared Function GetRecordsFromExcelSheet(ByVal strFilePath As String) As DataTable
Try
Dim strConnectionString As String
strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data source='" & strFilePath & "'; " & "Extended Properties=Excel 8.0;"
Dim outputTable = Nothing
Using conn As New OleDb.OleDbConnection(strConnectionString)
conn.Open()
Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim sheet As String = schemaTable.Rows(0)("TABLE_NAME").ToString()
Dim cmd As New OleDb.OleDbCommand("SELECT * FROM [" & sheet & "]", conn)
cmd.CommandType = CommandType.Text
Dim output As New DataSet()
outputTable = New DataTable(sheet)
output.Tables.Add(outputTable)
Dim objOleDbDataAdapter As New OleDb.OleDbDataAdapter(cmd)
objOleDbDataAdapter.Fill(outputTable)
End Using
Return outputTable
Catch ex As Exception
Throw ex
End Try
End Function