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 7714955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:15:55+00:00 2026-06-01T02:15:55+00:00

I am using a function to import data from a access db into SQL

  • 0

I am using a function to import data from a access db into SQL server:

public string importDataFromAccess(string table, string fileName)
    { 
        OleDbConnection OleDbConn = new OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", fileName));
        try
        {
            string sSQLTable = table;
            string myExcelDataQuery = "Select * from " + sSQLTable;
            string sSqlConnectionString = connStr;
            string sClearSQL = "DELETE FROM " + sSQLTable;
            SqlConnection SqlConn = new SqlConnection(sSqlConnectionString);
            SqlCommand SqlCmd = new SqlCommand(sClearSQL, SqlConn);
            SqlConn.Open();
            SqlCmd.ExecuteNonQuery();
            SqlConn.Close();

            OleDbCommand OleDbCmd = new OleDbCommand(myExcelDataQuery, OleDbConn);
            OleDbConn.Open();
            OleDbDataReader dr = OleDbCmd.ExecuteReader();
            SqlBulkCopy bulkCopy = new SqlBulkCopy(sSqlConnectionString);
            bulkCopy.DestinationTableName = sSQLTable;
            while (dr.Read())
            {
                bulkCopy.WriteToServer(dr);
            }
            OleDbConn.Close();
            return "Done";
        }
        catch (Exception ex)
        {
            OleDbConn.Close();
            return ex.ToString();
        }
    } 

I noticed it isnt importing the first record of each table, can anyone help notice why and how to fix? Hopefully it is only the first row…

  • 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-06-01T02:15:56+00:00Added an answer on June 1, 2026 at 2:15 am

    You shouldn’t need the

    while (dr.Read())
    {
         bulkCopy.WriteToServer(dr);
    }
    

    And you just need to replace that with

         bulkCopy.WriteToServer(dr);
    

    The WriteToServer method

    Copies all rows in the supplied IDataReader to a destination table
    specified by the DestinationTableName property of the SqlBulkCopy
    object.

    But the dr.Read() that you have called has read the first line out of the Reader and advanced the IDataReader to the next record (so it is not accessible to the WriteServer method).

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

Sidebar

Related Questions

I am trying to load a file using the SQL Server Import Data function
I'm using: import flash.utils.ByteArray; import mx.utils.Base64Encoder; import mx.utils.Base64Decoder; . . . public static function
I'm using the quantmod package to import financial series data from Yahoo. library(quantmod) getSymbols(^GSPC)
I'm trying to copy tables form a MS Access database into a SQL Server
Using the following code, I push data from an xml file into a classic
I am using the following code to import my data from XML to mySQL.
I have a class to import data from a CSV file, and a function
Using PyObjC, is it possible to import a Python module, call a function and
Using PyClips, I'm trying to build rules in Clips that dynamically retrieve data from
I have tried using a example file using PHPExcel script to extract data from

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.