Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 744519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:59:15+00:00 2026-05-14T08:59:15+00:00

My current project is to take information from an OleDbDatabase and .CSV files and

  • 0

My current project is to take information from an OleDbDatabase and .CSV files and place it all into a larger OleDbDatabase.

I have currently read in all the information I need from both .CSV files, and the OleDbDatabase into DataTables…. Where it is getting hairy is writing all of the information back to another OleDbDatabase.

Right now my current method is to do something like this:

    OleDbTransaction myTransaction = null;

    try
    {
        OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +
                                                   "Data Source=" + Database);
        conn.Open();
        OleDbCommand command = conn.CreateCommand();
        string strSQL;

        command.Transaction = myTransaction;

        strSQL = "Insert into TABLE " +
                 "(FirstName, LastName) values ('" +
                 FirstName + "', '" + LastName + "')";

        command.CommandType = CommandType.Text;
        command.CommandText = strSQL;

        command.ExecuteNonQuery();

        conn.close();

    catch (Exception)
        {
            // IF invalid data is entered, rolls back the database
            myTransaction.Rollback();
        }

Of course, this is very basic and I’m using an SQL command to commit my transactions to a connection. My problem is I could do this, but I have about 200 fields that need inserted over several tables. I’m willing to do the leg work if that’s the only way to go. But I feel like there is an easier method. Is there anything in LINQ that could help me out with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:59:16+00:00Added an answer on May 14, 2026 at 8:59 am

    If the column names in the DataTable match exactly to the column names in the destination table, then you might be able to use a OleDbCommandBuilder (Warning: I haven’t tested this yet). One area you may run into problems is if the data types of the source data table do not match those of the destination table (e.g if the source column data types are all strings).

    EDIT
    I revised my original code in a number of ways. First, I switched to using the Merge method on a DataTable. This allowed me to skip using the LoadDataRow in a loop.

    using ( var conn = new OleDbConnection( destinationConnString ) )
    {
        //query off the destination table. Could also use Select Col1, Col2..
        //if you were not going to insert into all columns.
        const string selectSql = "Select * From [DestinationTable]";
    
        using ( var adapter = new OleDbDataAdapter( selectSql, conn ) )
        {
            using ( var builder = new OleDbCommandBuilder( adapter ) )
            {
                conn.Open();
    
                var destinationTable = new DataTable();
                adapter.Fill( destinationTable );
    
                //if the column names do not match exactly, then they 
                //will be skipped
                destinationTable.Merge( sourceDataTable, true, MissingSchemaAction.Ignore );
    
                //ensure that all rows are marked as Added.
                destinationTable.AcceptChanges();
                foreach ( DataRow row in destinationTable.Rows )
                    row.SetAdded();
    
                builder.QuotePrefix = "[";
                builder.QuoteSuffix= "]";
    
                //forces the builder to rebuild its insert command
                builder.GetInsertCommand();
                adapter.Update( destinationTable );
            }
        }
    }
    

    ADDITION An alternate solution would be to use a framework like FileHelpers to read the CSV file and post it into your database. It does have an OleDbStorage DataLink for posting into OleDb sources. See the SqlServerStorage InsertRecord example to see how (in the end substitute OleDbStorage for SqlServerStorage).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my current project I have to send a signature from PHP to Java
My current project is broken down into 3 parts: Website, Desktop Client, and a
Our current project has ran into a circular dependency issue. Our business logic assembly
On my current project, which is a delivery system, I have a list of
for my current project i need to consume messages from many destinations (from hundreds
I cloned some of the trees from the Android Open Source Project to take
I have come to a roadblock in my current project. I basically have an
We have a current Java EE project and a new requirement to introduce a
My current project is using the IDesign architecture, so all of my layers are
So I have the view file complete for a current project and now I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.