Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-11-19
4
Medium Priority
?
51 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 83

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

722 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