C # ReportViewer with UnTyped datatable sources

I checked the history of questions, hit Google and other results, and am still completely puzzled by C # reportViewer. It seems that he only wants to work with "typed" datasets. As many other people asked, and I did not see real answers, maybe a new post will pull something new.

In its simplest form, I have a business object that executes a query from a database. I know what the resulting columns are, and I want it to connect to a specific report that is properly “formatted” as I need, unlike a simple column dump.

Since the query returns a "DataTable" object, but no known columns are "typed", I am closed.

As mentioned in other posts, if I have a system of 200 + tables, more than 400 views and more than 200 stored procedures, I do not want to enter everything. Especially if I make a NEW query, which is the result of separate tables associated with some new stored procedure.

It will not be easy to make a report. If I type the column or SUM (), COUNT () incorrectly or something is wrong, this is my mistake, but at least let me get the untyped table into the report.

Reference...

+3
source share
1 answer

No DataTable columns need to be entered; they can use the default value for a row.

, DataSet DataSet . . RDLC , DataSet , .

DataTable, , , DataSet ( , , DataTable ).

        DataTable dt = new DataTable();
        DataColumn dc = dt.Columns.Add();
        dc.ColumnName = "DataColumn1";

        dc = dt.Columns.Add();
        dc.ColumnName = "DataColumn2";

        dt.Rows.Add(new object[] { "Frank", 32 });

        this.reportViewer1.LocalReport.DataSources.Clear();
        this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1_DataTable1", dt));

        this.reportViewer1.RefreshReport();  

ReportViewer DataTable .

, ?

+3

Source: https://habr.com/ru/post/1727417/


All Articles