This is a migrated thread and some comments may be shown as answers.

DataTable not displayed in Telerik ReportViewer

3 Answers 169 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Subhasis
Top achievements
Rank 1
Subhasis asked on 08 Oct 2018, 07:27 AM

Hi,

    I am pretty new to Telerik Reporting and I am using C# WPF.  I have set a datatable to the DataSource of Report. The datatable is generated correctly with all rows from specified DB. But it is not displayed in ReportViewer.  Below is my code snippet. Please advise.

 

            Telerik.Reporting.Report myReport = new Telerik.Reporting.Report();
            string selectCommand = @"SELECT * FROM Angle";
            string connectionString = @"Data Source=IndianSections.db3";

            using (var connection = new SQLiteConnection(connectionString))
            {
                using(var command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = selectCommand;
                    using (var reader = command.ExecuteReader())
                    {                        
                        SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(selectCommand, connectionString);
                        DataTable dataTable = new DataTable();
                        dataTable.Load(reader);
                        //dataAdapter.Fill(dataTable);
                        
                        var objectDataSource = new Telerik.Reporting.ObjectDataSource();
                        objectDataSource.DataSource = dataTable;

                        myReport.DataSource = objectDataSource;
                        
                        var reportSource = new Telerik.Reporting.InstanceReportSource();
                        reportSource.ReportDocument = myReport;

                        this.reportViewer.ReportSource = (reportSource as ReportSource);
                        this.reportViewer.RefreshReport();
                    }    
                   // connection.Close();
                }
            }

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 11 Oct 2018, 06:58 AM
Hello Subhasis,

You need to create a report definition that inherits Telerik.Reporting.Report and contains report items, where to display the data - check How To: Create a Report (Visual Studio) article. From the code snippet I infer that myReport is an instance of Telerik.Reporting.Report, which is a base class and not a report definition.
In the code you correctly assign DataSource to myReport. However, in order to display the data from the DataSource, myReport should contain the appropriate report items (e.g. TextBoxes) bound to the Fields of the DataSource.
You can check our sample C# report definitions that come with the installation of Telerik Reporting and can be found in (Telerik Reporting installation folder)\Examples\CSharp (e.g. C:\Program Files (x86)\Progress\Telerik Reporting R3 2018\Examples\CSharp). The project CSharp.ReportLibrary contains multiple report definitions.

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Subhasis
Top achievements
Rank 1
answered on 11 Oct 2018, 11:01 AM

Thank you for your reply. I got most of the part. I have tried to add a panel and a textbox. And they are working fine. But can you please let me know how can I programmatically create a Telerik.Reporting.Table object and bind it to a System.Data.Datatable object which is already populated.

I need to bind the datatable to the Telerik.Reporting.Table object programatically to show it in tabular format.

0
Todor
Telerik team
answered on 16 Oct 2018, 08:11 AM
Hi Subhasis,

If it is necessary to crate a Table or other report item programmatically, I suggest to create the corresponding report in the Visual Studio report designer, and check the auto-generated method InitializeComponent() that contains the report definition - it can be found in the ReportName.Designer.cs/vb file. There you can find all the necessary settings for creating a report item and configuring its properties programmatically (as designed in the VS designer).

For DataSource of the Table item you can use a dedicated ObjectDataSource component bound to the DataTable object as explained in How to: Bind to a DataTable article.

Note that we do *not* recommend to create or modify reports programmatically.
Generally, the required run-time modifications can be achieved using Report Parameters in Expressions for Bindings, Conditional Formatting, etc. This approach features benefits like less programming and easier maintenance as all the bindings between the report items and data sources are carried internally by the Reporting engine. Hence, upon future changes in our API it will be more straight-forward to upgrade, as the migration to the new API will be handled in our code.

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Subhasis
Top achievements
Rank 1
Answers by
Todor
Telerik team
Subhasis
Top achievements
Rank 1
Share this question
or