如何在Crystal Report + C#中的两个表中显示两个不同的查询结果

问题描述:

大家好,



我在MSAccess下面有桌子



ID名称分类

1 John ASE

2 Kev ASE

3 Paul ASE

4 Lina SSE

5 Hendry SSE



我需要在一个Crystal Report中的两个表中显示结果

1)一个表用于类别为ASE的名称

2)第二个表名为SSE的名字



我无法在一个表格中显示两个类别的详细信息



请建议我如何做到这一点。我使用C#作为语言生成这个水晶报告



这是脚本,我正在使用

Hi All,

I have below table in MSAccess

ID Name Category
1 John ASE
2 Kev ASE
3 Paul ASE
4 Lina SSE
5 Hendry SSE

I need to display result in two tables in one Crystal Report
1) one table for names with Category "ASE"
2) Second table for names with Category "SSE"

I can't display both categories details in one table

Please suggest how I can do this. I am using C# as language to generate this crystal report

Here is the script , I am using

//CrystalReport1 is main where I want to show subreport
//CrystalReport4 is subreport

CrystalReport1 ObjRpt;

CrystalReport4 ObjRpt1;
 
ObjRpt = new CrystalReport1();

ObjRpt1 = new CrystalReport4();

String StrQuery;

StrQuery="SELECT Id,Name,MemberRank FROM Members WHERE Cat=1";

OleDbDataAdapter adp = new OleDbDataAdapter(StrQuery.ToString(), ControlRules.ClsConnect.Conn);

                DataSet ds = new DataSet();

                int ctr = adp.Fill(ds);

                DataSet1 Ds = new DataSet1();

                adp.Fill(Ds, "Customer");

StrQuery="SELECT Id,Name,SubRank,Ratiopergrop,NHPL,((KLP_Num * 120) - 25) as "RHN_Number" FROM Members WHERE Cat=2";

               OleDbDataAdapter adp1 = new OleDbDataAdapter(result1.ToString(), ControlRules.ClsConnect.Conn);

                DataSet ds1 = new DataSet();

                int ctr1 = adp1.Fill(ds1);

                ds1.Tables[0].Rows.Add(0, "", 0, 0, 0, 0);

                DataSet6 Ds1 = new DataSet6();

                adp1.Fill(Ds1, "Customer1");

                ObjRpt1.SetDataSource(Ds1);

                ObjRpt.SetDataSource(Ds);

                ReportDocument crystalReport = new ReportDocument();

                ReportDocument crystalReport1 = new ReportDocument();

                crystalReport=ObjRpt;

                crystalReport1 = ObjRpt1;

crystalReportViewer1.ReportSource = ObjRpt;

你不需要显示两个Cristal报告中的不同表格



您所需要的只是按类别分组数据!

请参阅: Crystal Reports向导和专家 [ ^ ]



我需要警告你姓名是一个 MS Access的保留字 [ ^ ]。更改名称字段的名称!
You don't need to "display two different tables in Cristal Report"!

All what you need is to group data by Category!
Please, see: Crystal Reports Wizards and Experts[^]

I need to warn you: Name is a reserved word for MS Access[^]. Change the name of Name field!


首先,您必须创建两个报告(显示两个表),数据源列为您希望每个类别。

并创建一个包含除这两个表之外的所有其他数据的主报告,并将您首先创建的报告作为子报告插入主报告。

(如果您的报告不是一个复杂或巨大的报告,而不是创建三个报告,您可以将一个报告与表格插入另一个报告。)



然后从代码您可以使用两个不同的数据表为每个子报表设置数据源。



As

First you have to create two reports (to show two tables), with data source columns as you desire for each category.
And the create a main report with all other data except these two tables and insert the reports you have created first as sub reports to the main report.
(If your report is not a complicated or huge one, instead of creating three reports you can insert one report with table to other one.)

Then from code you can set data source for each sub report with two different data tables.

As
ReportDocument subReport1 = new ReportDocument();
SubreportObject subReportObject1;
subReportObject1= mainReoprtObject.ReportDefinition.ReportObjects["Subreport1"] as SubreportObject;
//"Subreport1" is the subreport object name in main report
subReport1 = subReportObject1.OpenSubreport("mySubreport1.rpt");
subReport1.SetDataSource(datatable1);

ReportDocument subReport2 = new ReportDocument();
SubreportObject subReportObject2;
subReportObject2= mainReoprtObject.ReportDefinition.ReportObjects["Subreport2"] as SubreportObject;
subReport2 = subReportObject2.OpenSubreport("mySubreport2.rpt");
subReport2.SetDataSource(datatable2);