title: Export dataset to the excel sheet in asp.net c#
body: <p>I tried to export the dataset which have 4 tables to the excel sheet, Unfortunately I can't. I have code to export data table to excel. So instead of dataset, I called the "ExportToExcel" function which I have in my code to export datatable to excel 4 times. But once it created the first sheet, it stops the control flow. Control doesn't call the second function ("ExportToExcel(dsResult.Tables[2], "AthleteSentCount");") Here is the code</p>
  
  <pre><code>protected void ExportToExcel(object sender, EventArgs e)
  {
       ExportToExcel(dsResult.Tables[3], "AthleteInboxCount");
       ExportToExcel(dsResult.Tables[2], "AthleteSentCount");
       ExportToExcel(dsResult.Tables[0], "CoachInboxCount");
       ExportToExcel(dsResult.Tables[1], "CoachSentCount");
  }
  
  void ExportToExcel(DataTable dt, string FileName)
  {
      if (dt.Rows.Count &gt; 0)
      {
          string filename = FileName + ".xls";
          System.IO.StringWriter tw = new System.IO.StringWriter();
          System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
          DataGrid dgGrid = new DataGrid();
          dgGrid.DataSource = dt;
          dgGrid.DataBind();
  
          //Get the HTML for the control.
          dgGrid.RenderControl(hw);
          //Write the HTML back to the browser.
          //Response.ContentType = application/vnd.ms-excel;
          Response.ContentType = "application/vnd.ms-excel";
          Response.AppendHeader("Content-Disposition", 
                                "attachment; filename=" + filename + "");
          this.EnableViewState = false;
          Response.Write(tw.ToString());
          Response.End();
      }
  }
  </code></pre>
  
  <p>If any body knows to export the dataset to the excel with the bar chart please help me. Else please give your solution to the problem.</p>