none
conditioned report RRS feed

  • Question

  •  Hi every one
    I developed an app. this app has a sql 2005 database. The database has a table for students details. This app has a report viewer. When I run the app and refresh the reportviewer, it shows all students. I don't want this. I want the app to allow the end user to write the number of the student,and then show that student's details only in the reportviewer.
    Thanks for your help.
    Friday, July 4, 2008 4:41 PM

All replies

  • I use this kind of solution: I filter default view of main table used as datasource for report, in form load I set a filter that empty dataview:

    reportFilter = " 1 = 2 "

    mainDV.RowFilter = Me.reportFilter

    ReportViewer1.LocalReport.DataSources(0).Value = Me.mainDV.ToTable

    ReportViewer1.LocalReport.Refresh()



    When user refresh report I calculate correct filter to apply to dataview:

    reportFilter = <write correct filter>

    mainDV.RowFilter = Me.reportFilter

    ReportViewer1.LocalReport.DataSources(0).Value = Me.mainDV.ToTable

    ReportViewer1.LocalReport.Refresh()


    C.

    Monday, July 7, 2008 9:21 AM
  •  
    mishsad said:

     Hi every one
    I developed an app. this app has a sql 2005 database. The database has a table for students details. This app has a report viewer. When I run the app and refresh the reportviewer, it shows all students. I don't want this. I want the app to allow the end user to write the number of the student,and then show that student's details only in the reportviewer.
    Thanks for your help.



    Ok, one simple way to do this, is to just pass the value in as a parameter.  Since the end user is going to write the number of the student, and that's all we need, this is all you "should" have to do.

    First in your report, create a parameter.

    To do that, open the report in the designer, right click in the blank area, and choose report parameters.

    Add a parameter, give it a name and set it's type.  You can probably just set it as a string.



    Now, your report already shows all the student in a table, what you want to do is apply a filter to that table.  Right click on the table, and choose properties.  Make sure your looking a the table properties, and not the properties for a cell or something.

    You should have a tab that says "Filters", click on that, and you'll notice you have an area for expression, operator, and value.

    Set the expression to:
      
    Fields!StudentIDField.Value

    Set the operator to:

    =

    Set the value to an expression, choose parameters, and then you should see the parameter you created, choose that.

    Parameters!studentParam.Value


    So basically, the table will now only show student's who have an ID equal to your parameter.

    Now, your report won't display if you don't provide the parameter to it, I'm going to assume your using an .RDLC, so here is the code example of how to provide the parameter.

        
     
    ReportParameter studentParam = new ReportParameter("studentParam", txtStudentID.text);                 //used for passing in Student ID  
    ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { studentParam});  //attaches our parameter  
     


    And really the only difference between my example and claudio's is that I filter in the report, and claudio filters before the data is provided to the report.  Either way is perfectly valid.

    Living my life at 123mph in 11.15 seconds
    • Edited by Blasty Monday, July 7, 2008 1:41 PM edited
    Monday, July 7, 2008 1:40 PM
  • Blast2hell said:

    And really the only difference between my example and claudio's is that I filter in the report, and claudio filters before the data is provided to the report.  Either way is perfectly valid.


    You're right but there is a big difference in performance and bandwidth usage.

    Using my solution you may load only strictly necessary data (as I do because I have reports based only huge remote tables) but you have to reload data at every report refresh, using Blast2hell's solution you load all data at first report render then you only have to set report filter.

    If you don't have a critical amount of data, Blast2hell's solution is much faster.

    C.
    Wednesday, July 9, 2008 7:50 AM