如何将字符串放在Crystal Reports中的选择公式中? [英] How to put a string in a Selection Formula in Crystal Reports?
问题描述
我在表格后面的代码中有一个选择公式,上面有crystalreportviewer。我试图在每个用户登录时显示不同的报告。当用户登录会话开始时。会话按其INST_ID进行。现在,当用户登录并单击打印按钮时,弹出打印预览并显示报告。显示的报告不是该用户的报告。它显示另一个用户的报告。有没有办法过滤用户INST_ID的报告。因此,当他们登录并点击打印时,它将显示该用户的报告预览?
这是我的代码,用于crystalreortviewer:
I have a Selection Formula in the code behind the form that has the crystalreportviewer on it. I am trying to display a different report for each user when they login. When a user logs in the session starts. The session goes by their INST_ID. Right now when a user is logged on and clicks the print button a print preview pops up and shows the report. The report that is displayed is not the report for that user. It is showing the report of another user. Is there a way to filter the reports by the users INST_ID. So when they log on and click print it will display the preview of the report for that user?
Here is my code behind for the crystalreortviewer:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using System.Web.UI.WebControls.WebParts;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
using System.Web.SessionState;
namespace SACSCOCLogin1._1
{
public partial class ReportFormA : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CrystalReportViewer1.Visible = true;
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/Reports/ReportA.rpt"));
crystalReport.SetDatabaseLogon
("Admin", "master22", @"SQL", "Hot");
CrystalReportViewer1.ReportSource = crystalReport;
CrystalReportViewer1.SelectionFormula = "{COCINST.inst_id} = '" + Session["inst_id"].ToString() + "'";
}
}
}
这是我点击时的错误打印按钮:
This is the error that I get when I click on the print button:
A number is required here. Details: errorKind Error in File FormAReport {F1AAC878-E2B7-4104-BE51-B9CC0023DD43}.rpt: Error in formula Record Selection: '{TableCOCINST.INST_ID} = '10960'' A number is required here. Details: errorKind
我在CR中没有选择公式。
I have no Selection Formula in CR.
推荐答案
您可以在Crystal Reports中的选择公式中放置一个字符串,例如:
{COURSE.title} ='M.tech'
首先打开报表:Crystal Reports 10 / 8.5中的ReportA.rpt然后直接在报表>中的{TableCOCINST.inst_id} = 10000中给出该公式。 SelectionFormula>记录
我告诉你使用记录选择公式编辑器 [ ^ ]。
请参阅此示例, Crystal报表 - 创建记录选择公式 [ ^ ]
INST_ID
的数据类型是什么?如果是字符串,则应使用下面的单引号括起值
I told you to check the formula using Record Selection Formula Editor[^].
See this example, Crystal reports - Creating Record Selection Formulas[^]
What's the datatype ofINST_ID
? If it's string then you should enclose value with single quote like below
CrystalReportViewer1.SelectionFormula = "{TableCOCINST.inst_id} = '10000'";
为什么要在两个事件中粘贴代码?从中删除代码Page_Load()
这篇关于如何将字符串放在Crystal Reports中的选择公式中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!