none
DataTable in ReportViewer RRS feed

  • Question

  •  

    Hello!

    Please Give solution. There is a DataTable, which is produced in the program. I want to display data from Datatable in ReportView without interaction with SQL. What you need to do?

    So far I am doing so:
            DataSet NewDataSet = new DataSet();
            DataTable DataTable1 = new DataTable("DT");

            DataTable1.Columns.Add("Name", typeof(string));
            DataTable1.Columns.Add("Count", typeof(int));

            for (int i = 0; i < 5; i++)
            {
                DataRow dr = DataTable1.NewRow();
                dr["Name"] = "qwe";
                dr["Count"] = i;

                DataTable1.Rows.Add(dr);
            }

            NewDataSet.Tables.Add(DataTable1);

            ReportViewer1.Visible = true;
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportDataSource sour = new ReportDataSource("ODS", DataTable1);
            ReportViewer1.LocalReport.DataSources.Add(sour);

    In DEFAULT.ASPX:

               <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
                Height="400px" Width="400px">
                <LocalReport ReportPath="Report1.rdlc">
                    <DataSources>
                        <rsweb:ReportDataSource DataSourceId="ODS" Name="ODS" />
                    </DataSources>
                </LocalReport>


    Error:

    A data source instance has not been supplied for the data source 'NewDataSet_DT'.

    What's my mistake?

    Monday, December 17, 2007 9:09 AM

All replies

  • When you created the report, at somepoint, you attached data to it from a dataset named NewDataSet and that dataset contained a table named DT


    So, your .RDLC file knows it needs this datatable that you aren't providing.

     

    you need the following

     

    ReportDataSource reportInfo = new ReportDataSource();

    reportInfo.Name = "NewDataSet_DT";//actual tabular data

    reportInfo.Value = NewDataSet.Tables[0];

    ReportViewer1.LocalReport.DataSources.Add(reportInfo);

     

     

     

    Monday, December 17, 2007 6:20 PM