title: Dynamically render a DataTable into a Winform using the SSRS ReportViewer Control
body: <h1>BACKGROUND</h1>
  
  <ul>
  <li>I'm writing a method that will (eventually) take as input a System.Data.DataTable and render it as an (simple,tabular) SSRS report into a Winform using the Microsoft's ReportViewer Control (<a href="http://www.gotreportviewer.com/" rel="nofollow noreferrer">http://www.gotreportviewer.com/</a>)</li>
  <li>In order to do this I need to (1) dynamically create an RDL file based on the DataTable (2) load the RDL into the ReportViewerControl (3) bind the ReportViewerControl to that DataTable</li>
  </ul>
  
  <h1>QUESTIONS</h1>
  
  <ul>
  <li>Ideally I would simply love a link to a sample that did all of the above - I have searched but have been unable to find one.</li>
  <li>Otherwise, I need some help specifically with #1 and #3 above.</li>
  <li>For #1 - Is there a simple way of generating an RDL file dynamically at runtime? (I have already starting writing code to emit the correct XML, but re-using something will same me some time)</li>
  <li>For #3 - It's unclear to me how to bind the ReportViewerControl to a DataTable I have locally. Most of the examples I found assume I that ReportViewer control will fetch data that is on a remote SQL server (which is to be expected) instead of getting it from a local DataTable.</li>
  </ul>
  
  <h1>CONTEXT</h1>
  
  <ul>
  <li>I'm only recently starting working with the ReportViewer control - I have found samples googling - but none seem to cover the full scenario</li>
  <li>I do not know the schema of the DataTable ahead of time. The DataTable's schema will not even be constant during calls to my method which will render it.</li>
  <li>I cannot use a different reporting control - I must use the ReportViewer control. If you do know of other reporting controls that make this task easy, please do let me know. Even if it doesn't solve my current problem, it's useful for later.</li>
  <li>The person viewing this report is an end-user and does not have any rights to publish RDL to a SSRS server</li>
  <li>The DataTable will already be sorted, filtered, etc. The types will all be simply values of strings, ints, doubles, and dates. The DataTable will be of reasonable size - 1-30 columns and have from 100 to 5000 rows. The DataTable is also being constructed locally (sometimes manually constructed via code) and is <em>not</em> retrieving data from some remote datasource.</li>
  <li>The data will always be rendered as a simple table (no charts, etc.). Later on I may need to add grouping</li>
  <li>I cannot switch to using HTML, XAML, etc to display the report - there are features in ReportViewer that I will eventually make use of that that HTML, XAML, etc do not have.</li>
  </ul>
  
  <h1>UPDATE ON 2010/01/15</h1>
  
  <p>Starting from Jon's answer below I was able to achieve what I needed. As he mentions the difficut part is learning the RDL XML schema and knowing what RDL elements to write to achieve the desired kind of report. </p>