title: How to insert (bind) DataTable to Excel Workbook (VS Excel 2010 Workbook Project)
body: <p>I have <code>WCF Service</code> that returns data as <code>DataTable</code> type. I want to insert this data into Excel workbook in the <code>Workbook_Startup</code> event.</p>
  
  <p>What is the best way to do it?</p>
  
  <p>(VS .NET 3.5 Excel 2010 Workbook Project)</p>
  
  <hr>
  
  <p>WCF Service code:</p>
  
  <pre><code>public DataTable GetQuarterTargetAchievement()
  {
      var dt = new DataTable("TargetAchievement");
  
      using (var conn = new SqlConnection(GetConnectionString()))
      {
          using (var da = new SqlDataAdapter("SELECT fld1, fld2, ... , fldN FROM dbo.ReportTable; ", conn))
          {
              da.Fill(dt);
          }
      }
  
      return dt;
  }
  </code></pre>
  
  <hr>
  
  <p>Client code:</p>
  
  <pre><code>var dt = proxy.GetQuarterTargetAchievement();
  </code></pre>