Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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
C#
//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;
Posted
Updated 16-May-14 20:53pm
v2
Comments
Herman<T>.Instance 12-May-14 14:03pm    
What have you tried?
RDBurmon 12-May-14 14:59pm    
I tried to create another crystal report and added that as subreport in main crystal report
but it didn't show result in subreport
I can see lable values but couldn't see any data

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!
 
Share this answer
 
Comments
RDBurmon 13-May-14 14:21pm    
I have totally different format for both results
1) In first result, I need to show only 3 columns
2) In second result, I need to show 6 columns

Could you please let me know how to show two different tables in crystal report?
Maciej Los 13-May-14 14:42pm    
RDBurmon 13-May-14 15:00pm    
Thanks, I have to attach data source to this subreport using C# so Do I need to update dataset in first report or in second report
in any case how I can bind data set to the subreport?
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);
 
Share this answer
 
v3
Comments
RDBurmon 17-May-14 2:52am    
I have updated question with script that I am using
Could you please suggest what I am doing wrong? With this code , I am able to display subreport in main report
But it doesn't show any data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900