title: C# Console Import Excel to SQL from folder
body: <p>I have this code and it works fine.</p>
  
  <pre><code>public partial class CS
  {
      static void LoadExcelMain(string excelPath)
      {
  
          string conString = string.Empty;
          string extension = Path.GetExtension(excelPath);
          switch (extension)
          {
              case ".xls":
                  conString = @PH_MM_ExcelDataReader.Properties.Settings.Default.Excel03ConString;
                  break;
              case ".xlsx":
                  conString = @PH_MM_ExcelDataReader.Properties.Settings.Default.Excel07ConString;
                  break;
          }
          conString = string.Format(conString, excelPath);
          using (OleDbConnection excel_con = new OleDbConnection(conString))
          {
              excel_con.Open();
              string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
              DataTable dtExcelData = new DataTable();
  
              dtExcelData.Columns.AddRange(new DataColumn[16] { new DataColumn("MMRequestNo", typeof(string)),
              new DataColumn("MaterialNumber", typeof(string)),
              new DataColumn("ProductionVersion",typeof(string)) });
  
              using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con))
              {
                  oda.Fill(dtExcelData);
              }
              excel_con.Close();
  
              string consString = @PH_MM_ExcelDataReader.Properties.Settings.Default.ConnString;
              using (SqlConnection con = new SqlConnection(consString))
              {
                  using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
                  {
                      sqlBulkCopy.DestinationTableName = @PH_MM_ExcelDataReader.Properties.Settings.Default.DBTable;
  
                      sqlBulkCopy.ColumnMappings.Add("MMRequestNo", "MMRequestNo");
                      sqlBulkCopy.ColumnMappings.Add("MaterialNumber", "MaterialNumber");
                      sqlBulkCopy.ColumnMappings.Add("ProductionVersion", "ProdVersion");
                      con.Open();
                      sqlBulkCopy.WriteToServer(dtExcelData);
                      con.Close();
                      File.Delete(@PH_MM_ExcelDataReader.Properties.Settings.Default.FileLocationPath + "\\Product_Costing_Template.xlsx");
                  }
              }
          }
      }
      static void Main(string[] args)
      {
             LoadExcelMain(PH_MM_ExcelDataReader.Properties.Settings.Default.FileLocationPath + "\\Product_Costing_Template.xlsx");
      }
  }
  </code></pre>
  
  <p>I also have two tables; one is for the content of the excel file and the other is for the details of the file. </p>
  
  <pre><code>tableName: FileDetails
  ---------------------------------
  |FileName|RequestDate|isDone|Logs|
  |--------|-----------|------|----|
  </code></pre>
  
  <p>What I want to do is to process according to the RequestDate with this program I have currently only the excel files with "PH" in the start of the filename  </p>