Solved

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

Posted on 2016-11-19
4
43 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 82

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

628 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