Click here to Skip to main content
15,072,735 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Is it possible to Show a rdlc report dynamically by giving any select query.

I want to give a functionality for user to create report by his own way.At the same time i will create a sql query for getting desired report through Microsoft Report viewer...

I know it is not easy but is there any chance??

Thanks
Posted

1 solution

Yes it is possible..

Just try this....:)

1).aspx.cs page
C#
protected void Page_Load(object sender, EventArgs e)
{
    DataSet ds = GetDataSet();
    ReportDataSource rds = new ReportDataSource("Orders", ds.Tables[0]);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rds);
    ReportViewer1.LocalReport.Refresh();

    GridView1.DataSource = ds;
    GridView1.DataBind();
}

private DataSet GetDataSet()
{
    var conString = ConfigurationManager.ConnectionStrings["dotnetConnectionString"];
    string strConnString = conString.ConnectionString;

    SqlConnection conn = new SqlConnection(strConnString);
    conn.Open();
    string sql = "Select * FROM Orders";

    SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();        
    ad.Fill(ds);

    return ds;
}


.aspx page

C#
<form id="form1" runat="server">
<div>
    <asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">
    </asp:scriptmanager>
    <rsweb:reportviewer id="ReportViewer1" runat="server" height="600px" width="800px" xmlns:rsweb="#unknown">
        <localreport reportpath="Reports\Report.rdlc">
            <datasources>
                <rsweb:reportdatasource />
            </datasources>
        </localreport>
    </rsweb:reportviewer>
    <asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
    </asp:gridview>
</div>
</form>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900