尝试为Crystal Report设置参数字段 [英] Trying to set Parameter Field for Crystal Report

查看:82
本文介绍了尝试为Crystal Report设置参数字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CR查看器,我在报告上有两个参数字段。我有代码,找到并获取正确的参数字段值,以填充报告。我正在为其中一个参数字段添加代码,我被卡住了。这是我的代码:



I have a CR viewer and I have two parameter fields on the report. I have the code behind to find and get the correct parameter field values in order to populate the report. I am adding the code behind for one of the parameter fields and I am stuck. Here is my code:

protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con.Open();
            TextBoxUser_ID.Text = Session["User_id"].ToString();
            CrystalReportViewer1.Visible = true;

            ReportDocument CrystalReport = new ReportDocument();
            ParameterField paramField = new ParameterField();
            ParameterFields paramFields = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

            paramField.Name = "User_id";
            paramField.Name = "Year";
            paramField.CurrentValues.Clear();
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = TextBoxUser_ID.Text;
            paramDiscreteValue.Value = TextBoxYear.Text;
            paramFields.Add(paramField);
            CrystalReportViewer1.ParameterFieldInfo = paramFields;

            CrystalReport.Load(Server.MapPath("FormFTEReport50.rpt"));
            string sessiontype = TextBoxUser_ID.Text;
            string sessiontype = TextBoxYear.Text;
            CrystalReport.SetParameterValue("User_id", TextBoxUser_ID.Text);
            CrystalReport.SetParameterValue("Year", TextBoxYear.Text);

            string sessionid = TextBoxUser_ID.Text;
            CrystalReport.SetParameterValue("User_id", TextBoxUser_ID.Text);
            CrystalReportViewer1.ReportSource = CrystalReport;
            con.Close();
        }
    }
}





我把火腿卡在字符串sessiontype部分。如何让报告填充年份和UserID中的正确数据?



I ham stuck on the string sessiontype section. How can I get the report to populate with the correct data from the year and UserID?

推荐答案

为什么两次做事?



Why are you doing things twice ?

paramDiscreteValue.Value = TextBoxUser_ID.Text;
paramDiscreteValue.Value = TextBoxYear.Text;

paramField.Name = "User_id";
paramField.Name = "Year";

string sessiontype = TextBoxUser_ID.Text;
string sessiontype = TextBoxYear.Text;


这篇关于尝试为Crystal Report设置参数字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆