title: How to copy DataTable to Excel File using OLEDB?
body: <p>I am writing a program send data to excel by using oledb.
  I used Update statement like next: </p>
  
  <pre><code>OleDbConnection MyConnection = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + GeneralData.excelPath + "';Extended Properties=Excel 8.0;")
  MyConnection.Open();
  OleDbCommand myCommand = new OleDbCommand();
  myCommand.Connection = MyConnection;
  myCommand.CommandType = System.Data.CommandType.Text;
   string sql = "Update [test$] set press = " + pointsProperties[i].Pressure + ", temp = " + pointsProperties[i].Temperature + " where id= " + id;
  myCommand.CommandText = sql;
  myCommand.ExecuteNonQuery();
  </code></pre>
  
  <p>The problem is I will use the sql statement more than 100 times, which takes much time, so I thought that using Data Table will take less time, so I wrote a code saving my data in data table like next:</p>
  
  <p>public static System.Data.DataTable ExcelDataTable = new System.Data.DataTable("Steam Properties");</p>
  
  <pre><code>static System.Data.DataColumn columnID = new System.Data.DataColumn("ID", System.Type.GetType("System.Int32"));
  static System.Data.DataColumn columnPress = new System.Data.DataColumn("Press", System.Type.GetType("System.Int32"));
  static System.Data.DataColumn columnTemp = new System.Data.DataColumn("Temp", System.Type.GetType("System.Int32"));
  
  public static void IntializeDataTable() // Called one time in MDIParent1.Load()
          {
              columnID.DefaultValue = 0;
              columnPress.DefaultValue = 0;
              columnTemp.DefaultValue = 0;
  
              ExcelDataTable.Columns.Add(columnID);
              ExcelDataTable.Columns.Add(columnPress);
              ExcelDataTable.Columns.Add(columnTemp);
          }
  
  public static void setPointInDataTable(StreamProperties Point)
          {
              System.Data.DataRow ExcelDataRow = ExcelDataTable.NewRow(); // Must be decleared inside the function
                                                                          // It will raise exception if decleared outside the function
              ExcelDataRow["ID"] = Point.ID;
              ExcelDataRow["Press"] = Point.Pressure;
              ExcelDataRow["Temp"] = Point.Temperature;
  
              ExcelDataTable.Rows.Add(ExcelDataRow);
          }
  </code></pre>
  
  <p>The problem is I don’t know :</p>
  
  <p>1-  Is the second way is faster?</p>
  
  <p>2-  How to copy the Data Table to the excel file?</p>
  
  <p>Thanks.</p>