title: Export DataTable C# To Access - Slow Issue - 1 Million rows & 29 columns
body: <p>I am currently working on a C# project to export a datatable from C# to an Access accdb file. </p>
  
  <p>For the exportation function, I am using this function which comes from another post: <a href="https://stackoverflow.com/questions/7070011/writing-large-number-of-records-bulk-insert-to-access-in-net-c">Writing large number of records (bulk insert) to Access in .NET/C#</a></p>
  
  <pre><code>public static void InsertDataIntoAccessTable_Version3(DataTable dtOutData, String DBPath, String TableNm)
          {
              DAO.DBEngine dbEngine = new DAO.DBEngine();
              Boolean CheckFl = false;
              DateTime start = DateTime.Now;
  
              try
              {
                  DAO.Database db = dbEngine.OpenDatabase(DBPath);
                  DAO.Recordset AccesssRecordset = db.OpenRecordset(TableNm);
                  DAO.Field[] AccesssFields = new DAO.Field[dtOutData.Columns.Count];
  
                  //Loop on each row of dtOutData
                  for (Int32 rowCounter = 0; rowCounter &lt; dtOutData.Rows.Count; rowCounter++)
                  {
                      AccesssRecordset.AddNew();
  
                      Console.WriteLine(rowCounter);
                      //Loop on column
                      for (Int32 colCounter = 0; colCounter &lt; dtOutData.Columns.Count; colCounter++)
                      {
                          // for the first time... setup the field name.
                          if (!CheckFl)
                              AccesssFields[colCounter] = AccesssRecordset.Fields[dtOutData.Columns[colCounter].ColumnName];
                          AccesssFields[colCounter].Value = dtOutData.Rows[rowCounter][colCounter];
                      }
  
                      AccesssRecordset.Update();
                      CheckFl = true;
                  }
  
                  AccesssRecordset.Close();
                  db.Close();
  
                  double elapsedTimeInSeconds = DateTime.Now.Subtract(start).TotalSeconds;
                  Console.WriteLine("Append took {0} seconds", elapsedTimeInSeconds);
              }
              finally
              {
                  System.Runtime.InteropServices.Marshal.ReleaseComObject(dbEngine);
                  dbEngine = null;
              }
          }
  </code></pre>
  
  <p>According to the another post, it exported 120,000 Rows - 20 columns in 4 seconds. However, I cannot achieve such performance in my case where the datatable contains 1 Million rows and 29 columns. According to my estimation, it takes more then 20 minutes to finish. </p>
  
  <p>On the other hand, I also came across another method using adatper but I cannot implement it yet. </p>
  
  <p>I would like to know whether you have other solutions, suggestions, or advice to perform a much faster exportation from C# datatable to Access table.</p>
  
  <p>For the technical environment, I am using Visual Studio 2017 32bit and Access 365. </p>
  
  <p>Thank you in advance. </p>