简体   繁体   English

将价值传递给水晶报告

[英]Passing the value to crystal report

I'm having a hard time to figure out how can i view or seen the values from Visual Studio 2010 C# to Crystal Report.. This is I want to be viewed my report in Crystal Report 我很难弄清楚如何查看或查看从Visual Studio 2010 C#到Crystal Report的值。这是我希望在Crystal Report中查看我的报告的方法。

As of ????(4:30PM): ????(December), ????(2011)
Juan Dela Cruz
Count:    10
Score:    5
Grade:    ????(50.00)

The code below is my button SEARCH to find out the summary of this particular employee. 下面的代码是我的SEARCH按钮,用于查找该特定员工的摘要。

            try
            {
                econ = new SqlConnection();
                econ.ConnectionString = emp_con;
                econ.Open();
                float iGrade = 0;
                float Grade = 0.00F;
                string Log_User;
                float Count, Score;
                string date = DateTime.Now.ToShortTimeString();
                ecmd = new SqlCommand("SELECT Log_User, Count = COUNT(Det_Score), Score = SUM(Det_Score) FROM MEMBER M,DETAILS D WHERE D.Emp_Id = M.Emp_Id AND Log_User like" + "'" + Convert.ToString(comEmployee.Text) + "'AND Month(Sched_Start) =" + "'" + Convert.ToInt32(iMonth) + "'AND Year(Sched_Start) =" + "'" + Convert.ToInt32(txtYear.Text) + "'GROUP BY Log_User", econ);
                ecmd.CommandType = CommandType.Text;
                ecmd.Connection = econ;
                dr = ecmd.ExecuteReader();
                while (dr.Read())
                {
                    if (dr == null || !dr.HasRows)
                    {
                        MessageBox.Show("No record found.", "Error");
                    }
                    else
                    {
                        Log_User = (string)dr["Log_User"];
                        Count = (dr["Count"] as int?) ?? 0;
                        Score = (dr["Score"] as int?) ?? 0;
                        try
                        {
                            iGrade = Score / Count;
                            Grade = iGrade * 100;
                        }
                        catch (DivideByZeroException)
                        {
                            Console.WriteLine("Exception occured");
                        }
                    }
                }
                econ.Close();

The code below is my Crystal Report in getting the values from my database: these are included: Log_User, Month and the Year.. 下面的代码是我的Crystal Report,用于从数据库中获取值:其中包括:Log_User,Month和Year。

                ParameterFields myParams = new ParameterFields();

                ParameterField name = new ParameterField();
                ParameterDiscreteValue valName = new ParameterDiscreteValue();
                name.ParameterFieldName = "@Log_User";
                valName.Value = comEmployee.Text;
                name.CurrentValues.Add(valName);
                myParams.Add(name);

                ParameterField month = new ParameterField();
                ParameterDiscreteValue valMonth = new ParameterDiscreteValue();
                month.ParameterFieldName = "@Month";
                valMonth.Value = Convert.ToInt32(iMonth);
                month.CurrentValues.Add(valMonth);
                myParams.Add(month);

                ParameterField year = new ParameterField();
                ParameterDiscreteValue valYear = new ParameterDiscreteValue();
                year.ParameterFieldName = "@Year";
                valYear.Value = Convert.ToInt32(txtYear.Text);
                year.CurrentValues.Add(valYear);
                myParams.Add(year);

                crystalReportViewer1.ParameterFieldInfo = myParams;

                crystalReportViewer1.ReportSource = CrystalReport81;

            }
            catch (Exception x)
            {
                MessageBox.Show(x.GetBaseException().ToString(), "Connection Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

All i want is to view my input parameters in the report and also the grade.. (all the values that have ????) I know there is someone there can help me to figure it out. 我只想在报告中查看我的输入参数以及成绩。.(所有具有????的值)我知道那里有人可以帮助我找出答案。 After this, I've done in my project. 之后,我就完成了我的项目。

 TextObject yr = (TextObject)CrystalReport81.ReportDefinition.Sections["Section3"].ReportObjects["Text1"];
                yr.Text = txtYear.Text;

FORM Textbox --> CRYSTAL REPORT Textbox 表单文本框->水晶报告文本框

By adding the code above will enable you to show the value you entered in the textboxes.. but first you should have an empty Textbox in your Crystal Report because that will catch the value you throw from your FORM Textbox 通过添加上面的代码,您可以显示在文本框中输入的值。.但是首先,您在Crystal Report中应该有一个空的文本框,因为这将捕获从FORM文本框中抛出的值

I hope it can help others.. as it helped me a lot.. 我希望它可以帮助其他人。因为它对我有很大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM