Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my Windows Forms Application, i want to create a report. i have created an .rdlc file and assigned it a "dummy" dataset as a datasource just to get the schema, as described here :

http://blogs.msdn.com/b/sqlforum/archive/2011/04/28/sql-reporting-services-ssrs-bind-dynamic-dataset-to-your-local-report-with-reportviewer.aspx[^]

i want to change datasource of my report dynamically in the code. i found many examples like the following:


private DataTable getData()
{
    DataSet dss = new DataSet();
    string sql = "";
    sql = "SELECT ID, CLIENT_ID, AGENT_ID FROM TBLMAILDELETED";
    OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
    da.Fill(dss);
    DataTable dt = dss.Tables[0];
    return dt;
}

private void runRptViewer()
{
    this.ReportViewer1.Reset();
    this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
    ReportDataSource rds = new ReportDataSource("dsNewDataSet_Table", getData());
    this.ReportViewer1.LocalReport.DataSources.Clear();
    this.ReportViewer1.LocalReport.DataSources.Add(rds);
    this.ReportViewer1.DataBind();
    this.ReportViewer1.LocalReport.Refresh();
}



i want to place similar code on a button click. my question is:
if i want to add a parameter whose value is entered in a textbox on the form, what is the best way to do it?

1- should i add it in code as a parameter in my DataAdapter, and then my query will have a where-clause that uses that parameter to filter results ?
2- should i create ReportParameter and add it to my .rdlc? if so: how will that change the code? and how should that affect my DataAdapter query?

thanks in advance
Posted
Updated 15-Mar-18 1:07am

1 solution

u should use .rdlc paremeters to filter the data from dataset


by using setparameters to add parameters to report, like

ReportViewer ReportViewer1 = GetReportViewer();
ReportParameter[] parameters = new ReportParameter[1];
parameters[0] = new ReportParameter("Search", Name);
ReportViewer1.LocalReport.SetParameters(parameters);

by that u can filter data from dataset.
ex:
in textbox I enter data and that value can take and pass as parameter and in filter write like :
expression operator value
=Fields!UserName.Value LIKE ="*" & Parameters!Search.Value & "*"
 
Share this answer
 

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