Protected Function ExcelConnection() As OleDbCommand
Try
' Connect to the Excel Spreadsheet
'Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
'"Data Source=" & Server.MapPath("~/ExcelImport.xls") & ";" & _
'"Extended Properties=Excel 8.0;"
Dim sMinAndSecond As String = Me.Second_Minute_of_Upload.Text 'workaround to stop file locking on the same name
Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("~/Temp/ExcelImport" & sMinAndSecond & ".xlsx") & ";" & _
"Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"""
' create your excel connection object using the connection string
Dim objXConn As New OleDbConnection(xConnStr)
objXConn.Open()
' use a SQL Select command to retrieve the data from the Excel Spreadsheet
' the "table name" is the name of the worksheet within the spreadsheet
' in this case, the worksheet name is "Members" and is expressed as: [Members$]
Dim objCommand As New OleDbCommand("SELECT * FROM [Sheet1$]", objXConn)
Return objCommand
Catch ex As Exception
Response.Write("There was an error connecting to the Excel spreadsheet! " & Err.Description & " xk6")
End Try
End Function
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.