Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am able to connect a ReportViewer into my rep.aspx page that generate report of a database table named finalResult. this table have two field named stdId and subTotal. My ReportViewer show every data of this two field, but I want to filter the data, like only those stdId that have subTotal more than 40. I don't know anything about ReportViewer Please help me.
Posted

1 solution

You have to filter your data according to your business logic.So You can check below mentioned articles for get more knowledge about how to do that.

Sample for Data filtering :

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
        Customers dsCustomers = GetData("select top 20 * from customers");
        ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(datasource);
    }
}
 
private Customers GetData(string query)
{
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;
 
            sda.SelectCommand = cmd;
            using (Customers dsCustomers = new Customers())
            {
                sda.Fill(dsCustomers, "DataTable1");
                return dsCustomers;
            }
        }
    }
}


For more info : Local SSRS Reports or in other words RDLC Reports

Dynamic Binding Of RDLC To ReportViewer

I hope this will help to you.
 
Share this answer
 
v2
Comments
sazzad37 27-Oct-13 8:49am    
Customers dsCustomers = GetData("select top 20 * from customers");
I got an error into at Customers on this line of code. what is Customers here? Please help me?
Sampath Lokuge 27-Oct-13 9:03am    
This is a just a sample.Here customer is the Table name.You have to change it according to your data base details. Plz read the 2 articles which I have shared with you.

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