title: Generate and Design Rdlc file programmatically
body: <p>I'm doing mvc reporting and i'm very new at it. I'm trying to create a report, and i have done it using rdlc. Everything works well, it can be exported to various format. My problem, when using rdlc is that we need to design and bind it first. How can i create an empty rdlc template, design and bind it with dataset programmatically.</p>
  
  <p>My work so far (using <strong>empty rdlc template</strong> - just created the file without any table), </p>
  
  <p><strong>Controller File,</strong> </p>
  
  <pre><code>public ActionResult Report(string id)
      {
          DB.Open();
          LocalReport lr1 = new LocalReport();
          string path1 = Path.Combine(Server.MapPath("~/Report"), "TestEmptyReport.rdlc");
          lr1.ReportPath = path1;
          DataTable pc2a = new DataTable();
          pc2a = DB.getDataSet().Tables[0];
          pc2a.Columns.Add("Product Name");
          pc2a.Columns.Add("Price");
          pc2a.Columns.Add("Quantity");
          ReportDataSource rdc = new ReportDataSource("DataSet1", pc2a);
          lr1.DataSources.Add(rdc);
  
          string reportType = id;
          string mimeType;
          string encoding;
          string fileNameExtension;
  
          string deviceInfo =
  
              "&lt;DeviceInfo&gt;" +
              "&lt;OutputFormat&gt;" + id + "&lt;/OutputFormat&gt;" +
              "&lt;PageWidth&gt;8.5in&lt;/PageWidth&gt;" +
              "&lt;PageHeight&gt;11in&lt;/PageHeight&gt;" +
              "&lt;MarginTop&gt;0.5in&lt;/MarginTop&gt;" +
              "&lt;MarginLeft&gt;1in&lt;/MarginLeft&gt;" +
              "&lt;MarginRight&gt;1in&lt;/MarginRight&gt;" +
              "&lt;MarginBottom&gt;0.5in&lt;/MarginBottom&gt;" +
              "&lt;/DeviceInfo&gt;";
  
          Warning[] warnings;
          string[] streams;
          byte[] renderedBytes;
  
          renderedBytes = lr1.Render(
              reportType,
              deviceInfo,
              out mimeType,
              out encoding,
              out fileNameExtension,
              out streams,
              out warnings);
  
          return File(renderedBytes, mimeType);
  
      }
  </code></pre>
  
  <p><strong>Model File,</strong></p>
  
  <pre><code>public DataSet getDataSet()
      {
          string query = "SELECT * FROM tblproduct";
          if (con.State.ToString() == "Open")
          {
              SqlDataAdapter ad = new SqlDataAdapter(query, con);
              DataSet ds = new DataSet("tblproduct");
  
              ad.Fill(ds);
  
              return ds;
          }
          else
          {
              return null;
          }
      }
  </code></pre>
  
  <p><strong>View File,</strong></p>
  
  <pre><code>&lt;div style="padding: 10px; border: 1px solid black"&gt;
  &lt;div&gt;&lt;a href="@Url.Action("Report", new { id = "PDF" })"&gt;Get PDF Report&lt;/a&gt;&lt;/div&gt;
  &lt;div&gt;&lt;a href="@Url.Action("Report", new { id = "Excel" })"&gt;Get Excel Report&lt;/a&gt;&lt;/div&gt;
  &lt;div&gt;&lt;a href="@Url.Action("Report", new { id = "Word" })"&gt;Get Word Report&lt;/a&gt;&lt;/div&gt;
  &lt;div&gt;&lt;a href="@Url.Action("Report", new { id = "Image" })"&gt;Get Image Report&lt;/a&gt;&lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>The data is there, but i just dont know how to connect it with rdlc. Means creating column based on the data and fill it with the data called from sql server.</p>
  
  <p>TQVM in advanced. Explanation and example or any other method will be helpful.</p>