title: How to Pass Data Table to SSRS Report Viewer?
body: <pre><code>using (SqlConnection conn = new SqlConnection(connection))
  {
      SqlDataAdapter da = new SqlDataAdapter();
      DataTable ds = new DataTable();
  
      SqlCommand cmd = new SqlCommand();
      cmd.Connection = conn;
  
      conn.Open();
  
      cmd.CommandText = StoredProcedure;
      cmd.CommandType = System.Data.CommandType.StoredProcedure;
      cmd.Parameters.Add(new SqlParameter("@iDomainID", 1));
  
      foreach (var item in reportParams)
      {
          cmd.Parameters.Add(new SqlParameter("@" + item.ParameterName, "'" + item.FieldValue + "'"));
      }
  
      da.SelectCommand = cmd;
      da.Fill(ds);
  
      conn.Close();
  
      string strFile;
      strFile = "Reports/" + ReportName;
  
      ReportViewer1.Visible = true;
      System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Server.MapPath("/") + strFile);
      string strReportdef = sr.ReadToEnd();
      sr.Close();
  
      ReportViewer1.LocalReport.EnableExternalImages = true;
      ReportViewer1.LocalReport.ReportPath = HttpContext.Current.Server.MapPath("/") + strFile;
  
      int iTables = 0;
      System.Collections.Generic.IList&lt;string&gt; ilReportDSs =   ReportViewer1.LocalReport.GetDataSourceNames();
  
      for (iTables = 0; iTables &lt; ds.Columns.Count; iTables++)
      {
          ReportDataSource rdSource = new ReportDataSource(ilReportDSs[iTables], ds.Columns[iTables]);
          ReportViewer1.LocalReport.DataSources.Add(rdSource);
      }
  
      ReportViewer1.DataBind();
  }    
  </code></pre>
  
  <p>This causes an error in</p>
  
  <pre><code>for (iTables = 0; iTables &lt; ds.Columns.Count; iTables++)
  {
      ReportDataSource rdSource = new ReportDataSource(ilReportDSs[iTables], ds.Columns[iTables]);
      ReportViewer1.LocalReport.DataSources.Add(rdSource);
  }
  </code></pre>
  
  <p>For <code>ReportDataSource rdSource = new ReportDataSource(ilReportDSs[iTables], ds.Columns[iTables]);</code></p>
  
  <p>How should I pass data table to report viewer? Tried to change it to data set but this throws error for excecution of stored procedure using data set how will I pass using data table..? </p>