How to Copy Data from Oracle DB to Access DB in C#?

Posted on 2006-06-25
Last Modified: 2008-01-09
I have the same exact table structure in both the Oracle DB and the Access DB. Both DBs are installed in one PC which my C# (.NET 2.0) application will run from. However, the Oracle DB is the source one. So what I want is to copy a portion from the source Oracle DB (the portion is a specific SQL SELECT statement) to the Access DB.

I could get the data from the Oracle DB using an OracleDataAdapter and store the data in a DataTable, like this:
    OracleDataAdapter da = new OracleDataAdapter("SELECT * FROM R151BTS WHERE BSC=1, MyConnection);
    DataTable dt = new DataTable("dt");

But after that, how could I copy the data from the DataTable 'dt' to the Access DB?

I might be wrong with my above procedure, so if anyone could suggest to me an optimized way to do my request, I will be really grateful.
Question by:salan_alani
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
  • 3
LVL 41

Accepted Solution

graye earned 500 total points
ID: 16979101
The task becomes simplier  if the destination database is empty (or at least won't have any primary key collisions)...

In that case you merely "share the DataTable" between the two DataAdapters (one for Oracle and one for Microsoft Access).  Here is some "psuedo-code"

// Fill the dataTable from Oracle

// Mark all of the rows as "added"
foreach (DataRow myRow in DataTable.Rows)
         myRow.GetAdded();  // new to v2.0

// Save to Access with a separate DataAdapter

The task is a wee bit more complicated if you need update existing data in the destination database... you'd have to do a fill() followed by a Merge() before the Update()
LVL 41

Expert Comment

ID: 16979104
Damn... that's supposed to bet "SetAdded()"

I should check my spelling before I hit Submit, eh?

Author Comment

ID: 16979127
graye, I did not try your code yet. But, the Access DB is not empty. However, it does not have any primary key or some rules (it is a basic/simple table structure). Although, I don't need to update my existing data in the Access DB, just a matter of copying data from Oracle DB to Access DB.

So, should your code works for me?

Another thing, how should I create the DataAdapter2 object in my case? And does the Update method will affect the Access table itself without the need to do SQL INSERT INTO statement?

Thanks in advance
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.


Author Comment

ID: 16979394
graye, I tried your code and it works for me. However, I have the following error:

System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement

at the following block:

catch (Exception ex)
    SW.WriteLine("Error performing the update process: " + ex.Message);

Above is kind of logging the errors (SW is a StreamWriter object).

The problem is how could I know which DataRow through the exception? In other words, what is the SQL INSERT INTO statement that cause the problem? ex.Message or ex.ToString() do not have the information on which Row is not inserted/added !!!

Please reply me as soon as possible and thanks for your help..

Author Comment

ID: 16979664
I figure out the problem and solve it.

Thanks for your help..
LVL 41

Expert Comment

ID: 16980911
I'm glad you figured it out.... and I'm sorry my answer wasn't complete enough.

Yes, you have to either create the InsertCommand (and perhaps DeleteCommand) or use the CommandBuilder to create them for you.

I would imagine that you'd create the DataAdapter for the Microsoft Access database using the same technique ythat you used for the Oracle database.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Build a string of emails from a gridview 2 30
Stop Git from being my repository 1 48
aspx ascx, c# 7 42
What is GIS method of Geometry data type? 6 33
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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