I have users that name their sheets all sorts of crazy things, but I want to be able to get the first sheet of the Excel document regardless of what it is named.
I
You can get sheet1 name like this and use in this manner.If you want to get other sheet names you can increase value from 0,1,2..
Dim myExcelConn As OleDbConnection = _
New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
Server.MapPath(".") & "\" & FileUpload1.FileName() & _
";Extended Properties=Excel 12.0;")
Dim Sheets As DataTable = myExcelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Sheet1 = Sheets.Rows(0)("TABLE_NAME").ToString()
Dim objOleDB As New OleDbCommand("SELECT *FROM [" + Sheet1 + "]", myExcelConn)