ReportViewer on the fly?

Posted on 2006-05-24
Last Modified: 2010-04-16
Simply, I have a DataSet/DataTable which is filled from a specific and dynamic SQL Select statement, how could I view that Table in a ReportViewer control (not CrystalReportViewer control). Below my code:

string MyConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="Customers.mdb";

DataSet ds = new DataSet();

OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Customers", MyConnectionString);
// The SQL Select statement above could be anything else (I am getting it from user's input)

da.Fill(ds, "dt");

// What code should I put here so that the DataTable 'dt' could be viewed in the ReportViewer control


I am new on ths issue, and I am wondering if I could do this on the fly (dynamically/programatically) because I am not using any DataSource on my application. My application is just to print a given (dynamic) DataTable.
I am using C# .NET 2.0

Question by:salan_alani
    LVL 6

    Accepted Solution

    It is possible to do this, but its not very easy...

    There is an example (source code) on doing this at, titled Generate RDLC dynamically - Table
    LVL 2

    Author Comment

    Thanks e1v,

    Do you have any article link on this issue, cause what I have here is only the source code without even any descriptions/comments on it.
    Is this the only way or could be something else more easier cause I think the application should be easy just take a given DataTable then print it. I did before some class to print the DataGridView control with its style and it works fine except I was having some problems in wrapping issue, then I decided to take the advantage of the ReportViewer control cause I think it's the ideal way to do such stuff.

    So if anyone could help with some articles and source code about this issue.
    LVL 12

    Assisted Solution


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now