Solved

VB.Net - Read Excel file into Oracle table Error - External Table is not the expected format

Posted on 2016-11-19
4
27 Views
Last Modified: 2016-11-24
I am trying to read a csv file into an Oracle table using BulkCopy.  I had done this with SQL and pretty straight forward, but with Oracle, once I get to the code
excelstrCon.Open()
I get the error that
Table is not the expected format.

So not sure what's going on.  I am reading an excel csv file using Office 2003.  I did install the AccessDatabaseEngine.  Not sure what else I need to do.  Can someone look at the below code snippit and let me know what I am missing?

 Try
            'Connection string
            Dim excelCon As String
            Dim conString As String = GetConnectionString()


            '2007 & 2010 connection string
            excelCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtFile.Text + ";Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"""

            Dim excelstrCon As New OleDb.OleDbConnection(excelCon)
            excelstrCon.Open()


            'Create objects and get data
            Dim cmd As New OleDb.OleDbCommand("SELECT [ID], [NAME], [ADDRESS], [CITY], [STATE], [ZIPCODE] FROM [sheet1$] ", excelstrCon)
            Dim reader As OleDb.OleDbDataReader = cmd.ExecuteReader


            'open the destination data
            Dim dbCon As OracleConnection = New OracleConnection(conString)

            dbCon.Open()

            Dim bulkCopy As OracleBulkCopy = New OracleBulkCopy(dbCon)

            bulkCopy.DestinationTableName = "CUSTOMER_ADDRESS"
            bulkCopy.BulkCopyTimeout = 500
            bulkCopy.WriteToServer(reader)
            reader.Close()

            MsgBox("Complete")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Open in new window

0
Comment
Question by:holemania
  • 3
4 Comments
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41894315
that error means that the database table is expecting say a date format and you are passing to it a string
0
 

Author Comment

by:holemania
ID: 41894347
Sorry I missed the word "External" in my error I mentioned.  The error indicate "External Table is not the expected format".  It does not even get to the part where it is reading the query and doing the bulkload.  I get that error as soon as it gets to the following code.

excelstrCon.Open()

So it does not even know which table from Oracle I am doing the data load.  Something up with reading from the excel spreadsheet and thinking it's my connection string with Excel that caused the error.
0
 

Accepted Solution

by:
holemania earned 0 total points
ID: 41894354
Okay that was dumb of me.  It's a CSV file, once i change it to xls format, it's fine.
0
 

Author Closing Comment

by:holemania
ID: 41900318
Found out the issue was formatting of the excel file.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question