none
Parameters -- just don't get it. RRS feed

  • Question

  • I have read at least 200 entries on this forum and visited about as many websites but still haven't been able figure out how to pass a parameter to a reportviewer.  I found the perfect example on gotreportviewer.com -- the sample called Parameter prompting in local mode.  Unfortunately is uses C#, which is like Greek to me, and has a CVS file as the data source.  Gimme a break, who uses CVS files as a data source?  When I tried to adapt the code using a dataset based on a SQL database, I got 15 error messages!

    I know I am missing something simple. Is there anyone willing to really dumb-it down for me and explain step-by-step how to do it?

    I want to use dropdown control on the page where the user selects a date.  I want the selected value to filter the data shown reportviewer.  I have tried all the code samples I have found on this forum and elsewhere to no avail.

     

    Thanks,

    Neal

    Tuesday, July 17, 2007 10:27 PM

Answers

  • Good for you, perservering and finding (a) a sample that actually used dates and (b) something in VB since that encourages your attempts. To answer your question about what you put in for the param, I don't think it matters what you put in as the prompt because it's going to be hidden in local mode anyway, right?

     

    From your description of what you did and experienced, I think -- although I am not 100% certain -- that I may see what your real problem is.

     

    In local mode, your code is providing the dataset.  It's not like servermode where there is a SELECT query or whatever embedded in the report and when you refresh the report the query is re-run with your conditions -- presumably applied by using the parameters in your queries -- in place.

     

    In local mode, you have bound your dataset to your report externally.  You could reload the data, with your conditions in place, externally to the report -- and then when you refreshed the report you would see your filtered set.

     

    In local mode, when you expect a parameter to do the work *within* the report, you need to tell the report to filter the data using a different mechanism.  It doesn't prepare the dataset, you already did. 

     

    OK so far?

     

    So: you give the parameter to the report, and I think you probably have this part right although I'm a bit concerned about why it didn't "take" the first time.  (You should probably make sure this parameter has a valid default value.)

     

    Now you tell the report to filter by setting a filter condition on the actual layout elements (or "data regions") that use the dataset. 

     

    In your case, the "data region" is a matrix, right? So select the matrix in your layout.  Right click -- if you haven't really selected the matrix, but rather some contained element, you should have a choice in the rightclick menu that allows you to select 'matrix1' or whatever. (You should also be able to see that your matrix is the selected object by looking at the Properties window.)

     

    At any rate, with your matrix selected, choose Properties from the bottom of the rightclick menu. See the Filters tab in the dialog?  That's where you want to apply your parameter.

     

    Now, going back to your C# sample, you can see this if you look at the RDLC, so you really don't ever need to look at any C# code <g>.

     

     I'm going to dump the XML for the table definition directly from the RDLC here, in lieu of a picture, excuse me for doing it but I want you to see the filter expression that s/he put on the filter for the table in his/her layout, similar to what I'm saying you need to do for your matrix: 

    Code Snippet

    <Table Name="table1">

       <Left>0.25in</Left>

       <Filters>

          <Filter>

             <Operator>Equal</Operator>

             <FilterValues>

                <FilterValue>=Parameters!City.Value</FilterValue>

             </FilterValues>

             <FilterExpression>=Fields!City.Value</FilterExpression>

          </Filter>

       </Filters>

       <DataSetName>Customer</DataSetName>

       <!-- etc... -->

     

     ... see?

     

    HTH,

     

    >L<

     

     

     

     

    Wednesday, July 18, 2007 4:31 PM

All replies

  • Hello Neal,

     

    I think maybe it would be best if you post the code you have written that does not work and tell us what the error is. Somebody will be able to spot the problem pretty quickly.

     

    You say yourself that you've read a lot of posts.  There are a lot of ways to explain this and potentially, I guess, a lot of things that can go wrong -- so another "tutorial in mid air" about how to do it will just be the 201st post on the subject you've read; not necessarily pertinent to what is really going on with you. (It's also a lot to ask people to just write a treatise on the off-chance that we'll hit the culprit in the process of concocting a full step by step explanation <s>.)

     

    Let us try to narrow down what could be wrong by seeing what you're doing and we'll probably have better luck <s>.

     

    I will say that it might be something as simple as date format getting in the way, because you say you are using a date and that often happens... but this might be a red herring.  Again, what is the error, what occurs when you try, etc?

     

    As for the gotreportviewer.com sample... while I agree that it overcomplicates the thing it is trying to show with a lot of extraneous code, a lot of people like a fully-posable sample.  Often that requires including the data in a portable form so that anybody can build and run the form and it will work. I might do it as XML, this person did it as CSV, but it basically doesn't matter where the data came from.

     

    You shouldn't need to "adapt the code to use a SQL database".  Where the lookup data comes from should be irrelevant to understanding the few (maybe six) lines of code in which the sample actually talks to report parameters.  And while that six lines of code is, yes, written in C#, they will be almost exactly the same code in VB.  So post those lines of code as you've written them in VB, tell us what's going wrong, and it will probably be something we can figure out right away.


    OK?   Keep your chin up <s>.

     

    >L<

     

    Wednesday, July 18, 2007 5:05 AM
  • Lisa,

    Your reply was so calm, cool and reasoned I almost believe I will solve this thing (with your help).

     

    My latest attempt was based on the code found in this posting: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=288075&SiteID=1

     

    I changed it to match my nomenclature:

     

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim pub As Microsoft.Reporting.WebForms.ReportParameter
            Dim pubdate As DateTime = TextBox1.Text

            pub = New Microsoft.Reporting.WebForms.ReportParameter("Dated", pubdate)
            Me.ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WebForms.ReportParameter() {pub})
            ReportViewer1.LocalReport.Refresh()

        End Sub

     

    When I open the page, I get an error message saying there has been no parameter value provided, which is fine. I will deal with that later.  

    But after entering the parameter and clicking the button, the report opens displaying all the data, not data filtered by the parameter.  I added the parameter to the report, but I am not sure I did it correctly.  I put Dated as the name, DateTime as the data type and Textbox1.text as the prompt. Is that correct? 

    I would use a gridview or some other control, but I need to use a maxtrix.

    I won't include my effort to adapt the C# code since the example has a string parameter and I need to use a datetime.  As you suggest, the data type could cause complications, presumably avoided by the "borrowed" VB code above that originally dealt with a datetime parameter.

    Again, thanks for your reassurances and patient response.

    Neal

     

     

    Wednesday, July 18, 2007 3:37 PM
  • Good for you, perservering and finding (a) a sample that actually used dates and (b) something in VB since that encourages your attempts. To answer your question about what you put in for the param, I don't think it matters what you put in as the prompt because it's going to be hidden in local mode anyway, right?

     

    From your description of what you did and experienced, I think -- although I am not 100% certain -- that I may see what your real problem is.

     

    In local mode, your code is providing the dataset.  It's not like servermode where there is a SELECT query or whatever embedded in the report and when you refresh the report the query is re-run with your conditions -- presumably applied by using the parameters in your queries -- in place.

     

    In local mode, you have bound your dataset to your report externally.  You could reload the data, with your conditions in place, externally to the report -- and then when you refreshed the report you would see your filtered set.

     

    In local mode, when you expect a parameter to do the work *within* the report, you need to tell the report to filter the data using a different mechanism.  It doesn't prepare the dataset, you already did. 

     

    OK so far?

     

    So: you give the parameter to the report, and I think you probably have this part right although I'm a bit concerned about why it didn't "take" the first time.  (You should probably make sure this parameter has a valid default value.)

     

    Now you tell the report to filter by setting a filter condition on the actual layout elements (or "data regions") that use the dataset. 

     

    In your case, the "data region" is a matrix, right? So select the matrix in your layout.  Right click -- if you haven't really selected the matrix, but rather some contained element, you should have a choice in the rightclick menu that allows you to select 'matrix1' or whatever. (You should also be able to see that your matrix is the selected object by looking at the Properties window.)

     

    At any rate, with your matrix selected, choose Properties from the bottom of the rightclick menu. See the Filters tab in the dialog?  That's where you want to apply your parameter.

     

    Now, going back to your C# sample, you can see this if you look at the RDLC, so you really don't ever need to look at any C# code <g>.

     

     I'm going to dump the XML for the table definition directly from the RDLC here, in lieu of a picture, excuse me for doing it but I want you to see the filter expression that s/he put on the filter for the table in his/her layout, similar to what I'm saying you need to do for your matrix: 

    Code Snippet

    <Table Name="table1">

       <Left>0.25in</Left>

       <Filters>

          <Filter>

             <Operator>Equal</Operator>

             <FilterValues>

                <FilterValue>=Parameters!City.Value</FilterValue>

             </FilterValues>

             <FilterExpression>=Fields!City.Value</FilterExpression>

          </Filter>

       </Filters>

       <DataSetName>Customer</DataSetName>

       <!-- etc... -->

     

     ... see?

     

    HTH,

     

    >L<

     

     

     

     

    Wednesday, July 18, 2007 4:31 PM
  • Lisa,

    Eureka!  You've done it. Thank you very much. I did not realize I needed to set the parameter on the report and the matrix.

    Neal 

     

     

     

    Wednesday, July 18, 2007 5:52 PM
  • Well, now I'm hoping you understand not only that you need to do it... but also *why* <g>.

     

    Have fun,

     

    >L<

    Wednesday, July 18, 2007 6:36 PM