开发者

Displaying data dynamicall through report viewer in asp.net

开发者 https://www.devze.com 2023-03-27 22:18 出处:网络
Hi all, I want to display data generated by a query in a report dynamically. I have written the following code in page load event:

Hi all, I want to display data generated by a query in a report dynamically. I have written the following code in page load event:


protected void Page_Load(object sender, EventArgs e)
    {
        string sqlQuery = "select * from Login";
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RosterConnecti开发者_运维技巧onString"].ConnectionString);
        SqlDataAdapter da = new SqlDataAdapter(sqlQuery, con);

        DataTable dt = new DataTable();
        da.Fill(dt);

        ReportDataSource rds1 = new ReportDataSource("Reports_Login", dt);
        DReportViewer.Reset();
        DReportViewer.LocalReport.ReportPath = Server.MapPath("MyReport.rdlc");
        DReportViewer.LocalReport.DataSources.Clear();
        DReportViewer.LocalReport.DataSources.Add(rds1);
        DReportViewer.DataBind();

        DReportViewer.LocalReport.Refresh();
    }

The following code is written in aspx file:

<form id="form1" runat="server">
    <div>
        <rsweb:ReportViewer ID="DReportViewer" runat="server">
        </rsweb:ReportViewer>
    </div>
</form>

But when I run the page, It gives an error stating

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


Please help me out ASAP....


This means that a Datasource on your report called "Login_Login" has not been set to an instance.'

Do you have only one Datasource on your Report? If so try to change the name of your ReportDataSource to "Login_Login" like this

  ReportDataSource rds1 = new ReportDataSource("Login_Login", dt);

The name you give the instance has to match the name of the datasource you have defined in the report

If you have multiple Datasources in your report, please add instances to all of them. Like I do in this example

        LocalReport report = new LocalReport();
        report.DataSources.Add(new ReportDataSource("Login_Login", (DataTable)ds.LoginTable));
        report.DataSources.Add(new ReportDataSource("Report_Login", (DataTable)ds.ReportLoginTable));
        report.DataSources.Add(new ReportDataSource("Report_Another_One", (DataTable)ds.AnotherTable));
0

精彩评论

暂无评论...
验证码 换一张
取 消