0
votes

First, I'm just beginning to learn reporting, all these versions of Crystal Report is confusing me. Anyway, I used the built in Crystal Reports in VS2008.

I am following this tutorial. I am having a problem filtering. I need to apply two parameter fields to my report - to sort it according to user type or user status. I have these in a cmb box and a textbox beside it to enter text and filter the report upon button click.

  1. When I applied the filter code to my system (upon button click). The initial code to load the entire report without filters did not work (on formload). It shows a pop up asking me to enter parameter values.
  2. The filter worked great.. until I added another parameter field and tried to duplicate the effect. I went through the same process. Add a parameter field, right click > Report > Selection Formula > Record selection and then added another line. It didnt work.

In my records selection formula editor, it looks like this.

{UserType.UserType} = {?UserType}
{UserStatus.UserStatus} = {?UserStatus}

I believe I do not know how to assign it to a parameter field. And I dont know how to use the records selection formula editor.

I want the UserType Parameter field to have this parameter {UserType.UserType} = {?UserType} and the UserStatus Parameter field to have {UserStatus.UserStatus} = {?UserStatus}

I need help, I don't know how to phrase my question properly for google. This is my code for the button click. I know the code just repeats itself. If you know of an easier way to do this, please advise.

    private void ShowReport_Btn_Click(object sender, EventArgs e)
    {
        //IF SELECTED
        if (Filter_cmb.SelectedItem.ToString() == "UserType") 
        {
            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();

            cryRpt.Load("D:\\MY_THESIS\\WORKING FILES\\WindowsFormsApplication2\\WindowsFormsApplication2\\Reports\\Crystal Reports\\UsersReport.rpt");
            crConnectionInfo.ServerName = "RITZEL-PC\\SQLEXPRESS";
            crConnectionInfo.UserID = "NNIT-Admin";
            crConnectionInfo.Password = "password";
            crConnectionInfo.DatabaseName = "NNIT DB";

            Tables CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = textBox1.Text;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["UserType"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();
        }
        else if (Filter_cmb.SelectedItem.ToString() == "UserStatus") 
        {
            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();

            cryRpt.Load("D:\\MY_THESIS\\WORKING FILES\\WindowsFormsApplication2\\WindowsFormsApplication2\\Reports\\Crystal Reports\\UsersReport.rpt");
            crConnectionInfo.ServerName = "RITZEL-PC\\SQLEXPRESS";
            crConnectionInfo.UserID = "NNIT-Admin";
            crConnectionInfo.Password = "password";
            crConnectionInfo.DatabaseName = "NNIT DB";

            Tables CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = textBox1.Text;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["UserStatus"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();
        }
1

1 Answers

2
votes

Your record-selection formula needs to be:

{UserType.UserType} = {?UserType}
AND {UserStatus.UserStatus} = {?UserStatus}

Also, ensure that each of the parameter's data type matches the value of the referenced database field.