Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I put a parameter call 'Title' in my report. When I load the page, it show a message stated 'The 'Title' parameter is missing a value' error appear. When I click button to active the reportviewer, this message appear again. If I click button to active the control, then the error will disappear, and function normally.
What can I do to solve this?

private void BindReport()
{
    string strregion="";
    if (cbAll.Checked)
    {
        strregion = "a.region_cd <>''";
    }
    if (cbListOnly.Checked)
    {
        strregion = " a.region_cd like '" + ddlArea.SelectedItem.Value + "%'";
    }

    using (MySqlConnection conn = new MySqlConnection(cnstr))
    {
        conn.Open();

        string areadt = "SELECT a.*,b.*,c.*  From school as a left join (ref_region as b, lecturer as c,school as d) " +
            "on (a.region_cd=b.cd and a.lecturer_id=c.lecturer_id) " +
           "WHERE " + strregion + " and a.established_dt between " + "'" + ddlSYear.SelectedValue + "-" + ddlSMonth.SelectedValue + "-01' and '" + ddlEYear.SelectedValue + "-" + ddlEMonth.SelectedValue + "-31' and " +
            "a.school_type_cd='2'  ORDER BY a.origination_temple_id,a.established_dt";
        MySqlDataAdapter data = new MySqlDataAdapter(areadt, conn);
        data.Fill(dt);
        conn.Close();
    }
    rptViewer1.LocalReport.DataSources.Clear();
    ReportDataSource rptData = new ReportDataSource("DataSet1", dt);
    LocalReport r = new LocalReport();
    r.ReportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "~/ReportForm/JTListByArea.rdlc");
    r.DataSources.Add(rptData);
    rptViewer1.LocalReport.DataSources.Add(rptData);
    rptViewer1.LocalReport.ReportPath = Server.MapPath("~/ReportForm/JTListByArea.rdlc");
    rptViewer1.LocalReport.Refresh();
}

and source:
<rsweb:ReportViewer ID="rptViewer1"  runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana"
    WaitMessageFont-Size="14pt" Style="margin-right: 116px" Width="1200px" DocumentMapCollapsed="False" PageCountMode="Actual"
    PromptAreaCollapsed="True">
    <LocalReport ReportPath="ReportForm\JTListByArea.rdlc">
    </LocalReport>
</rsweb:ReportViewer>
Posted
Updated 11-Jan-16 3:31am
v2
Comments
[no name] 9-Jan-16 9:23am    
Can you share relevant what happens in button click and how data is binding to reportviewer..
Patrice T 10-Jan-16 1:57am    
You can show relevant code.
Member 12115140 11-Jan-16 9:32am    
I had put the code to the question
Richard Deeming 11-Jan-16 12:44pm    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Member 12115140 12-Jan-16 3:46am    
Thank you for your advise

1 solution

Agree with what people are saying regarding the sql injection etc... however to get back to the op question...!

Where do you declare your report parameters?

Normally I do something like:...

VB.NET
Dim rptParameter As ReportParameter
rptParameter = New ReportParameter("Title", "Report Title Name")

rptViewer1.LocalReport.SetParameters(rptParameter)


Without checking this may need to be an array of parameters...
 
Share this answer
 
v3
Comments
Member 12115140 14-Jan-16 21:44pm    
It work! Thank you very much!

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