473,466 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to make a subreport in .net

51 New Member
hi,


i want to create a subreport.i tried many ways bt am nt able to get the right output.
can please ne1 tell me how to go about it systematically.
thanx.

the task is xplained here in detail.
ex:

i hv a main report which gets displayed on th click of a item in a form in .net.

nw ths main report have fields.

class division students

3 A 23
4 b 43


now the task is...if i click on students..suppose 43 thn i should get a new report which will show the
name age

of students..
similarly if i click on 23 i need to get a report which displays the names of students from 3 class of div b.

so can ne i tell me hw to go about it....

thanx..
Mar 2 '07 #1
6 3960
kenobewan
4,871 Recognized Expert Specialist
Please provide more information about platform, language, errors etc.
Mar 3 '07 #2
Smish
51 New Member
The crystal report which am using is embedded in .net vs 2003 .
c# ..
thanx..
Mar 5 '07 #3
hodgesp
7 New Member
Depending on how you conect to the database you use the connection for the main report and pass it to the sub report. I found the easiest way is to use a SQLDataAdapter and DataSet in design mode. The Adapter handles the connection and all you have to do is cycle through the sections of the report.

Here is some sample C# code: Note crReport1 is the Main Report, crSubRptName is the SubReport. Make sure the tables for the main report and the tables for the SubReport are included in DataSet1

SAMPLECode
Expand|Select|Wrap|Line Numbers
  1. this.sqlCommand1.Connection = sqlConnection1; 
  2. this.sqlCommand1.CommandType = CommandType.Text; 
  3. this.sqlCommand1.CommandText="Select * From Table1 Where Field1 
  4. = " + someValue;
  5.  
  6. this.DataSet1.Clear(); 
  7.  
  8. this.sqlDataAdapter1.SelectCommand = this.sqlCommand1; 
  9. this.sqlDataAdapter1.Fill(this.DataSet1,"Tabl1");
  10. this.crReport1.SetDataSource(this.DataSet1);
  11. //---subreport script---//
  12. Sections crSections;
  13. crSections = this.crReport1.ReportDefinition.Sections;                              
  14. ReportObjects crReportObjects;
  15. SubreportObject crSubreportObject;
  16. ReportDocument crSubRptName  = new ReportDocument();                              
  17. foreach (Section crSection in crSections) 
  18. {
  19.  crReportObjects = crSection.ReportObjects;
  20.    foreach (ReportObject crReportObject in crReportObjects) 
  21.     {
  22.       if (crReportObject.Kind == ReportObjectKind.SubreportObject) 
  23.          {
  24.             crSubreportObject = (SubreportObject)crReportObject; 
  25.             crSubreportObject.OpenSubreport( crSubreportObject.SubreportName).SetDataSource(this.DataSet1);
  26.         }
  27.      }
  28. }
  29.  
  30. this.CrystalReportViewer1.ReportSource = this.crReport1; 
  31. this.crReport1.PrintOptions.PaperOrientation = PaperOrientation.Landscape;//
  32. this.crReport1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;   //
  33. this.CrystalReportViewer1.DataBind();                             
  34.  
  35. //---pdf export code---//
  36. System.IO.BinaryReader strStream;
  37. strStream = new BinaryReader(crReport1.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat));
  38. Response.ClearContent();
  39. Response.ClearHeaders();
  40. Response.ContentType = "application/pdf"; Response.BinaryWrite(strStream.ReadBytes(Convert.ToInt32(strStream.BaseStream.Length)));
  41. Response.Flush();
  42. Response.Close();
Mar 5 '07 #4
radcaesar
759 Recognized Expert Contributor
For this, drill down reports using datagrid will be enough (with the help of table relationships) No need for crystal reports.

:)
Mar 5 '07 #5
Smish
51 New Member
hi all..
thanx..

but my requirement is to use crystalreports....
Mar 6 '07 #6
hodgesp
7 New Member
I use Crystal in my applications too. In fact I had a hard time finding code that worked for me as well but I finally did.

Add the tables, views, or stored procedure to the dataset in the design mode. Create your reports; main and subreport, then try the code I previously submitted. Substituting the name of your reports where noted. I also included some script to automatically export the report to pdf. You can take that out or attach it to a seperated button control if you want.

good luck.
Mar 6 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steve Edwards | last post by:
I am trying to use an existing report as a subreport in another report. I have the subreport added to the main report, but the only thing that shows up where the subreport should be is the name of...
9
by: Downstreamer | last post by:
Design is as follows: A form for the user to input criteria to be used as the where part of the report's recordsource. This includes a multiselect list box as part of the criteria selection. ...
7
by: Ellen Manning | last post by:
I've got an A2K report showing students and their costs. Student info is in the main report and costs are in a subreport for each student. The user inputs the program desired then only those...
6
by: Steve Jorgensen | last post by:
I tried to fix a problem for a client today in which report sections and even individual text controls in some of their reports are being split across page boundaries. Of course, I was thinking...
1
by: shaqattack1992-newsgroups | last post by:
I know this is kind of a weird question, but is there anyway to give a subreport control of a main report? I posted my situation earlier about having drawings print out after a group. I have a...
5
by: Tom | last post by:
I have a subreport that can contain one or two pictures per page. The subreport is similar to an appendix to the main report. The recordsource contains a field "IncludeInReport" (Yes/No) for each...
0
by: C | last post by:
Hi, I have a main Report which has a SubReport. This SubReport also has a SubReport. I set the data of my main Report and Subreport through code DataSet dsMainReport =...
1
by: pdm | last post by:
hoi access, I have a subreport and with the id of inheritance of OOP I like to reuse this subreport in other main reports and hide some fields. First, is this possible and second what is the...
11
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Master Report is: Me.RowSource = "TableOrQueryName"
3
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RecordSource of a Master Report is: Me.RecordSource = "TableOrQueryName"
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.