首先,我刚刚开始学习报告,所有这些版本的Crystal Report都让我感到困惑。无论如何,我在VS2008中使用了内置的Crystal Reports。
我关注this tutorial。我有过滤问题。我需要在报表中应用两个参数字段 - 根据用户类型或用户状态对其进行排序。我将它们放在一个cmb框和旁边的文本框中输入文本,并在点击按钮时过滤报告。
在我的记录选择公式编辑器中,它看起来像这样。
{UserType.UserType} = {?UserType}
{UserStatus.UserStatus} = {?UserStatus}
我相信我不知道如何将它分配给参数字段。我不知道如何使用记录选择公式编辑器。
我希望 UserType参数字段具有此参数{UserType.UserType} = {?UserType} 并且 UserStatus参数字段要{UserStatus.UserStatus} = {?UserStatus}
我需要帮助,我不知道如何正确地为谷歌说出我的问题。这是我点击按钮的代码。我知道代码只是重复了一遍。如果您知道更简单的方法,请提供建议。
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();
}
答案 0 :(得分:2)
您的记录选择公式必须是:
{UserType.UserType} = {?UserType}
AND {UserStatus.UserStatus} = {?UserStatus}
此外,请确保每个参数的数据类型与引用的数据库字段的值匹配。