根据ID生成报告 [英] Generating report based on ID

查看:107
本文介绍了根据ID生成报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序中有一个水晶报表,其中显示了所有员工及其薪水.
我希望报告仅显示特定员工的薪水
因此我创建了一个表单(frmMysalary),该表单仅使用特定人员的ID.
我如何编码此表单并将其链接到Crystal报告,以便基于在frmMysalary中输入的ID生成报告

请帮帮我

OP的其他信息从下面的非解决方案中移出
创建了报表,然后在字段资源管理器"的参数字段"(Crystal Reports)中创建了一个新的Integer参数.
然后,我通过在Crystal Reports设计器窗口上单击鼠标右键,选择REPORT->,为Crystal Reports创建选择公式.选择公式->记录.

首先,我从学生"表中选择了"studentid"的表字段,然后选择了比较运算符(=),最后选择了我先前创建的参数.
代码

I have a crystal report in my program that displays all staffs and their salary.
I want the report to display only the salary of a particular staff
so I created a form (frmMysalary) which only takes the ID of a particular staff.
How do I code and link this form to the crystal report so that the report is generated base on the ID entered into frmMysalary

please help me out

OP''s additional information moved from non-solution below
created the report then I created a new Integer parameter in the Parameter Fields of Field Explorer (Crystal Reports).
I then created the selection formula for the Crystal Reports by Right clicking on Crystal Reports designer window , select REPORT -> SELECTION FORMULA -> RECORD .

first i selected the table field that is studentid from Student table and then I selected the comparison operator (=) and finally i selected the Parameter i created earlier.
The code

 private void btnShowreport_Click(object sender, EventArgs e)
 {
 ReportDocument cryRpt = new ReportDocument();
 cryRpt.Load("F:\\STUDENT\\STUDENT\\CrystalReport2.rpt");
  
 
ParameterFieldDefinitions crParameterFieldDefinitions;
 ParameterFieldDefinition crParameterFieldDefinition;
 ParameterValues crParameterValues = new ParameterValues();
 ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
  
 //crParameterDiscreteValue.Value = Convert.ToInt32(txtStudentrid.Text);
 crParameterDiscreteValue.Value = txtStudentrid.Text;
 crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
 crParameterFieldDefinition = crParameterFieldDefinitions["studentid"];
 crParameterValues = crParameterFieldDefinition.CurrentValues;
  
 crParameterValues.Clear();
 crParameterValues.Add(crParameterDiscreteValue);
 crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
  
 crystalReportViewer2.ReportSource = cryRpt;
 crystalReportViewer2.Refresh();
 }

推荐答案

表格 frmMysalary
private void print_Click(object sender, EventArgs e)
        {
           datatable tbl= new datatable();
           SqlDataAdapter adp = new SqlDataAdapter("select * from staffdetails where staffID='"+textbox1.text+"'",conn);
           adp.fill(tbl);
           if(dt>0)
           {
                Reports.StaffReport sr = new Reports.StaffReport ();
                sr.dt = tbl;
                sr.Show();
           }
           else
           {
                   MessageBox.Show("No Records found");
           }
         }



表格 StaffReport



Form StaffReport

public DataTable dt = new DataTable();
        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            Reports.StaffReport crt = new Reports.StaffReport();
            crt.Database.Tables[0].SetDataSource(dt);
            crystalReportViewer1.ReportSource = crt;
        }


这篇关于根据ID生成报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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