简体   繁体   English

Export Filtered data from crystal report to pdf using c# windows form application

[英]Export Filtered data from crystal report to pdf using c# windows form application

I'm new to using crystal report in c# windows form application.I connect my crystal report to mysql server "11.0.65.185".我是 c# windows 表单应用程序中使用水晶报表的新手。我将我的水晶报表连接到 mysql 服务器“11.0.65.185”。

I have (EmpName, EmpId, DOB, DOJ, Address, City) this 6 column in my crystal report.我的水晶报告中有(EmpName、EmpId、DOB、DOJ、地址、城市)这 6 列。 then i add a parameter in my report as (fromdate and todate)然后我在我的报告中添加一个参数(fromdate 和 todate)

this link helps me to filter the DOJ column http://stackoverflow.com/questions/37391112/filter-data-in-crystal-report-using-datetimepicker/37525275#37525275 thanks to stackoverflow.感谢 stackoverflow,此链接帮助我过滤 DOJ 列http://stackoverflow.com/questions/37391112/filter-data-in-crystal-report-using-datetimepicker/37525275#37525275

but here i have the problem in Export option.但在这里我在导出选项中遇到了问题。 I have maximum 1000 data's.我最多有 1000 个数据。 When i filter data in DOJ using Datetimepicker1 has fromdate and Datetimepicker2 as todate i got an between data's into my report.当我使用 Datetimepicker1 在 DOJ 中过滤数据时,从日期开始,而 Datetimepicker2 作为日期,我在报告中得到了一个介于两者之间的数据。

I need to export only that filter data's.But when i search through googling i got an code to export full data's which are present in my database table.我只需要导出过滤数据。但是当我通过谷歌搜索时,我得到了一个代码来导出存在于我的数据库表中的完整数据。

CrystalReport1 crys = new CrystalReport1();
crys.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\\Users\\Downloads\\ReportAsPDF.pdf");
                MessageBox.Show("Report Export Into PDF File");

This code help me export whole data in c# crystal report.此代码帮助我导出 c# 水晶报表中的全部数据。 Please Friends Help Me to Export only filtered data into PDF.请朋友们帮我把过滤后的数据导出到PDF。

Thank You For Help.谢谢你的帮助。

Try this as same as filter data in report尝试与报告中的筛选数据相同

                TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
                TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
                ConnectionInfo crConnectionInfo = new ConnectionInfo();
                Tables CrTables;

                ParameterFieldDefinitions crParameterFieldDefinitions;
                ParameterFieldDefinition crParameterFieldDefinition;
                ParameterValues crParameterValues = new ParameterValues();
                ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

                crParameterDiscreteValue.Value = dateTimePicker1.Text;
                crParameterFieldDefinitions = crys.DataDefinition.ParameterFields;
                crParameterFieldDefinition = crParameterFieldDefinitions["fromdate"];
                crParameterValues = crParameterFieldDefinition.CurrentValues;

                crParameterValues.Clear();
                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

                crParameterDiscreteValue.Value = dateTimePicker2.Text;
                crParameterFieldDefinitions = crys.DataDefinition.ParameterFields;
                crParameterFieldDefinition = crParameterFieldDefinitions["todate"];
                crParameterValues = crParameterFieldDefinition.CurrentValues;



                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);


                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

                crConnectionInfo.ServerName = "****";
                crConnectionInfo.DatabaseName = "****"; ;
                crConnectionInfo.UserID = "root";
                crConnectionInfo.Password = "******";

                CrTables = crys.Database.Tables;
                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                {
                    crtableLogoninfo = CrTable.LogOnInfo;

                    CrTable.ApplyLogOnInfo(crtableLogoninfo);
                }
                DateTime date = DateTime.Now;
                int t = date.Hour;
                int t1 = date.Minute;
                int t2 = date.Second;
                int m = date.Month;
                int d = date.Day;
                int y = date.Year;

                crys.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\\Downloads\\ReportAsPDF Time" + t + " - " + t1 + " - " + t2 + " Date " + d + " - " + m + " - " + y + ".pdf");
                MessageBox.Show("Export Successfully");
  1. First you have to add these:首先你必须添加这些:
using MySql.Data.MySqlClient;
using CrystalDecisions.CrystalReports.Engine;
  1. Write that:写下:
MySqlConnection con = new MySqlConnection("datasource=172.16.2.104;port=3306;server=localhost;database=tourism_db;uid=root;password=;sslmode=none;charset=utf8;");
MySqlCommand cmd = new MySqlCommand();
ReportDocument cryRpt = new ReportDocument();

MySqlDataAdapter adap2;
cmd = con.CreateCommand();
ReportDocument cryRpt2 = new ReportDocument();
StrSearch = " SELECT * FROM `expenses_db`";
cmd.CommandText = StrSearch;
adap2 = new MySqlDataAdapter();
adap2.SelectCommand = cmd;
DataSet custDB2 = new DataSet();
custDB2.Clear();
adap2.Fill(custDB2, "Expenses_db");
myReport.SetDataSource(custDB2);

crystalReportViewer1.ReportSource = myReport;
crystalReportViewer1.Refresh();
cryRpt = myReport;

cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"C:\File1.pdf");   

暂无
暂无

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

相关问题 是否可以直接将Crystal报表保存为pdf格式,而无需从C#Windows Form应用程序在客户端PC中安装Crystal报表? - Is it possible to directly save crystal report to pdf format without installing crystal report in client pc from C# windows form application? 使用过滤后的数据馈送水晶报表C# - Feeding crystal report with filtered data c# C#Crystal Report使用图表导出为PDF - C# Crystal report export to PDF with Chart 从 CrystalReportViewer 按钮将 Crystal 报表导出为 PDF(使用 Asp.net c#) - Export Crystal report to PDF from CrystalReportViewer button (using Asp.net c#) 如何在Windows窗体应用程序中使用C#将Crystal Report连接到MS Access数据库 - How to connect Crystal Report to MS Access database using C# in Windows Form Application 如何在C#中将Crystal报表导出为PDF和电子邮件 - How to export Crystal report to PDF and email in c# 如何在C#2010中将Crystal报表直接导出为pdf? - How to export crystal report directly to pdf in c# 2010? 使用c#将Crystal报表导出为PDF时,仅500个文件中只有75个文件被导出 - Export in Crystal report to PDF only 75 files are exported out of 500 files using c# 如何使用C#在Crystal Report中显示3个表中的数据 - How to show data from 3 tables in crystal report using c# 如何在另一个 windows 表单或水晶报表 c# 中捕获项目级数据集 - How to capture project level data-set in another windows form or crystal report form c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM