Need to Import from csv not xls RRS feed

  • Question

  • User709978785 posted

    I use the following to import from an Excel xls file. I need to do the exact same thing, but using a csv file.

    Can anyone help?

                    'excel connection STRING
                    Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                    "Data Source=" & Server.MapPath("~/Import/ExcelUpload.xls") & ";" & _
                    "Extended Properties=Excel 8.0;"
                    ' create your excel connection object using the connection string
                    Dim objXConn As New OleDbConnection(xConnStr)
                    ' Get Sheet Name
                    Dim dtSheetName As DataTable = objXConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
                    'Use name of first sheet
                    Dim sSheetName As String = dtSheetName.Rows(0)("TABLE_NAME").ToString
                    ' retrieve the Select command for the Spreadsheet
                    Dim objCommand As New OleDbCommand("SELECT * FROM [" + (sSheetName + "]"), objXConn)
                    '  create a DataReader
                    Dim reader As OleDbDataReader
                    reader = objCommand.ExecuteReader()

    Friday, August 31, 2012 3:31 PM