简体   繁体   中英

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

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.

            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..

                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

I hope it can help others.. as it helped me a lot..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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