本文介绍了使用参数创建Crystal Report的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 亲爱的所有人, 我想在两个日期之间的特定任务中创建一个Crystal Report。在这里,我将通过以上三点。但我不能在两个日期之间得到报告。这是我的代码供您检查。请帮我找一些需要改变的地方。我的代码生成所有日期的报告。 private void button_Click() { ReportDocument cryRpt = new ReportDocument(); cryRpt.Load( @ Reports\DatewiseSupplierReport.rpt); frm_ReportForm _report = new frm_ReportForm(); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); 表格CrTables; SqlConnection con = new SqlConnection(); string [] conString = DBSettings.connectionStringValues(); string connectionString = string .Format( @ server = + conString [ 0 ] + ; database = restaurant; uid = + conString [ 2 ] + ; pwd = + conString [ 3 ]); con.ConnectionString = connectionString; con.Open(); crConnectionInfo.ServerName = conString [ 0 ]; crConnectionInfo.DatabaseName = restaurant; crConnectionInfo.UserID = conString [ 2 ]; crConnectionInfo.Password = conString [ 3 ]; ParameterFieldDefinitions crParameterFieldDefinitions; ParameterFieldDefinition crParameterFieldDefinition; ParameterValues crParameterValues = new ParameterValues(); ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = cmb_SupplierName.Text; crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields; crParameterFieldDefinition = crParameterFieldDefinitions [ SupplierName]; crParameterValues = crParameterFieldDefinition.CurrentValues; crParameterValues.Clear(); crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); crParameterDiscreteValue.Value = dateTimePicker1.Value.ToString(); crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields; crParameterFieldDefinition = crParameterFieldDefinitions [ fromDate]; crParameterValues = crParameterFieldDefinition.CurrentValues; crParameterValues.Clear(); crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); crParameterDiscreteValue.Value = dateTimePicker2.Value.ToString(); crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields; crParameterFieldDefinition = crParameterFieldDefinitions [ toDate]; crParameterValues = crParameterFieldDefinition.CurrentValues; crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); CrTables = cryRpt.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } crystalReportViewer2.ReportSource = cryRpt; crystalReportViewer2.Refresh(); } 在上面,我从combobox获得SupplierName(cmb_SupplierName) 我得到的两个日期是来自datetimepicker1和2. 预付谢谢 Dhinesh Kumar.V 解决方案 访问此链接 http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-dynamic-login.htm [ ^ ] Dear All,I want to create a Crystal Report in a particular task between two dates. Here I am passing all the above three. But I can''t get the report between two dates. Here is my code for you to check. Please help me find what needs to be changed. My code generates a report for all dates.private void button_Click(){ ReportDocument cryRpt = new ReportDocument(); cryRpt.Load(@"Reports\DatewiseSupplierReport.rpt"); frm_ReportForm _report = new frm_ReportForm(); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); Tables CrTables; SqlConnection con = new SqlConnection(); string[] conString = DBSettings.connectionStringValues(); string connectionString = string.Format(@"server=" + conString[0] + ";database=restaurant;uid=" + conString[2] + ";pwd=" + conString[3]); con.ConnectionString = connectionString; con.Open(); crConnectionInfo.ServerName = conString[0]; crConnectionInfo.DatabaseName = "restaurant"; crConnectionInfo.UserID = conString[2]; crConnectionInfo.Password = conString[3]; ParameterFieldDefinitions crParameterFieldDefinitions; ParameterFieldDefinition crParameterFieldDefinition; ParameterValues crParameterValues = new ParameterValues(); ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = cmb_SupplierName.Text; crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields; crParameterFieldDefinition = crParameterFieldDefinitions["SupplierName"]; crParameterValues = crParameterFieldDefinition.CurrentValues; crParameterValues.Clear(); crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); crParameterDiscreteValue.Value = dateTimePicker1.Value.ToString(); crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields; crParameterFieldDefinition = crParameterFieldDefinitions["fromDate"]; crParameterValues = crParameterFieldDefinition.CurrentValues; crParameterValues.Clear(); crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); crParameterDiscreteValue.Value = dateTimePicker2.Value.ToString(); crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields; crParameterFieldDefinition = crParameterFieldDefinitions["toDate"]; crParameterValues = crParameterFieldDefinition.CurrentValues; crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); CrTables = cryRpt.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } crystalReportViewer2.ReportSource = cryRpt; crystalReportViewer2.Refresh(); }In the above, I get SupplierName from combobox(cmb_SupplierName) The two dates I get are from datetimepicker1 and 2.Thanks in AdvanceDhinesh Kumar.V 解决方案 visit this linkhttp://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-dynamic-login.htm[^] 这篇关于使用参数创建Crystal Report的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-21 15:03