title: SSIS importing Excel data via C# to SQL Server
body: <p>I've just got started with SSIS and the processing of Excel files via C# when I stumbled over this article:</p>
  
  <p><a href="http://www.codeproject.com/Articles/368530/Dynamic-Excel-file-loading-with-SSIS" rel="nofollow">Link</a></p>
  
  <p>The article explains how to load Excel data via SSIS into a SQL Server database.</p>
  
  <p>But instead of some select statement I would need to have all the rows extracted starting from a specific row (for example row 9). Now my question is, what pieces of code do I need to change/erase in order to get me to set the starting row without the need of using any header information?</p>
  
  <pre><code>public SourceFileDetails ScanRows(DataSet excelDataSet, string ExtractionStatement, string FindColumn)
  {
          if (excelDataSet.Tables.Count &lt; 1)
              return (SourceFileDetails)null;
  
          string ExtractFields = this.ReplaceString(this.ReplaceString(ExtractionStatement, "SELECT", ""), "From [Data$]", "");
          List&lt;string&gt; FindStrings = ExtractFields.Split(',').Select(s =&gt; s.Trim().Replace("[", "").Replace("]", "").Replace("#", ".").Replace("(", "").Replace(")", "")).ToList();
  
          foreach (DataTable dt in excelDataSet.Tables)
          {
              List&lt;ItemValueHolder&gt; FoundAddress = new List&lt;ItemValueHolder&gt;();
              int iDuplicates = 0;
  
              foreach (DataRow dr in dt.Rows)
              {
                  int iItemColumnIndex = 0;
                  foreach (var fieldValue in dr.ItemArray)
                  {
                      object cellData = fieldValue;
                      string sCellData = cellData.ToString().Replace("#", ".").Replace("[", "").Replace("]", "").Replace("(", "").Replace(")", "");
  
                      if (cellData != null)
  
                          if (FindStrings.Exists(delegate(string k) { return k.ToLower() == sCellData.ToString().ToLower(); }))
                          {
                              if (!FoundAddress.Exists(delegate(ItemValueHolder t) { return t.Item.ToLower() == sCellData.ToLower(); }))
                                  FoundAddress.Add(new ItemValueHolder(sCellData, dt.Rows.IndexOf(dr), iItemColumnIndex));
                              else
                                  iDuplicates++;
                          }
                      iItemColumnIndex++;
                  }
                  int iTotalFields = FindStrings.Count - iDuplicates;
  
                  if (100 * FoundAddress.Count / (float)iTotalFields &gt;= 90.00)
                  {
                      var query = FoundAddress.GroupBy(
                  item =&gt; item.ItemValue,
                  (itemvalue, items) =&gt; new
                  {
                      Key = (int)itemvalue,
                      Count = items.Count(),
                  });
  
  
                      int dataStartAddress = (from p in query
                                              where p.Count == (query.Max(it =&gt; it.Count))
                                              select p.Key).Max();
                      dataStartAddress += 1;
                      string SheetName = "[" + dt.TableName + "$A" + dataStartAddress.ToString() + ":IV]";
                      string _selectCommand = this.ReplaceString(ExtractionStatement, "[Data$]", SheetName);
                      string reportDate = "";
                      if (!string.IsNullOrEmpty(FindColumn))
                          try
                          {
  
                              int ColIndex = (from p in FoundAddress
                                              where p.Item.ToLower() == FindColumn.ToLower()
                                              select p.ColumnIndex).First();
                              DataRow drRowReport = dt.Rows[dataStartAddress];
                              reportDate = drRowReport[ColIndex].ToString();
  
                          }
                          catch (Exception e)
                          {
                              //log 
                          }
                      string NewFields = GetNewFieldsAtSource(FindStrings, dr);
                      return new SourceFileDetails("", "", "", _selectCommand, reportDate, NewFields);
                  }
              }
          }
          return (SourceFileDetails)null;
      } 
  </code></pre>
  
  <p>Thanks a lot!</p>