|
|
 |
BOOK: Professional Crystal Reports for VS.NET  | This is the forum to discuss the Wrox book Professional Crystal Reports for Visual Studio .NET by David McAmis; ISBN: 9780764544033 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Professional Crystal Reports for VS.NET section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

December 7th, 2006, 12:11 AM
|
|
Registered User
|
|
Join Date: Dec 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Crystal Report Sub Report Using C#
Hi All,
I have built an application using C#.net and Crystal Reports which are exported to PDF. The reports I have been using have been running very well. I generate the report from a dataset at runtime (see code below)
I have tried to modify some of my reports to include a sub-report which I have built an run separately as a report first.
I have included the sub report in the details section of the main report and specified the link field. I get errors when I try to run it.
I do not know how to write the C# code to get the sub report to run from the main report.
I have been unable to find any examples anywhere on the net or in books. It must be quite simple because these sub-reports are very common.
The code I use to generate the main report is below. I mostly understand this. Could anybody be so kind as to show me how to modify my code below to include the sub-report in the main report.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
namespace ElecCon.Invoice.InvoiceItem1
{
/// <summary>
/// Summary description for InvoiceItemReport.
/// </summary>
public class InvoiceItemReport : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
string sSQLSelect;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected ElecCon.Invoice.InvoiceItem1.DataSet77 dataSet771;
protected System.Web.UI.WebControls.Button Button1;
InvoiceItemDetailReport report = new InvoiceItemDetailReport();
private void Page_Load(object sender, System.EventArgs e)
{
sSQLSelect = Session["ReportSelectionString"].ToString();
SetUpReport();
ExportTheReport();
}
private void SetUpReport()
{
try
{
DataSet dataSet771 = new DataSet();
string sSQL = "SELECT invoice_Item_UID, job_Pack_UID, proj_Account_No,cpm_No, contract_UID, contract_Abbr, contract_Descr, invoice_UID, quote, extra,complete, "+
"invoice_Comment, invoice_Date, invoice_Work_OH, invoice_Month, invoice_Year, progress_UID, progress, project_Name, project_Description, feeder, "+
"equipment, old_Pole_No, item_Completed_Date, assy_No, assy_Descr, assy_Descr_Short, cost_Code, uom, quantity, work_Kind_Abbr, "+
"work_Kind_Descr, company, company_Abbr, contractor, class_Abbr, class_Description, customer_UID, customer_Abbr, customer_Name, "+
"notification_Date, Price, age,extra_Type, comment, resource_Cost "+
" FROM dbo.vwInvoiceItems "+ sSQLSelect + "";
SqlConnection conn = new SqlConnection(ConnectDB.ConnectionString);
SqlCommand sqlCommand = new SqlCommand(sSQL, conn);
sqlCommand.CommandTimeout = 3600;
SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
da.Fill(dataSet771,"vwInvoiceItems");
report.SetDataSource(dataSet771);
}
catch(Exception ex)
{
string x = Request.Url.AbsolutePath.ToString();
Session["ErrorMessage"] = ex.ToString();
Session["OriginatingUrl"] = x;
Response.Redirect("..\\..\\ProcessError.aspx");
}
finally
{
}
}
#region Web Form Designer generated code
}
#endregion
private void ExportTheReport()
{
ExportOptions exportOpts = new ExportOptions();
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
string FName;
FName = "C:\\Temp\\JobPackReport.pdf";
diskOpts.DiskFileName = FName;
exportOpts = report.ExportOptions;
exportOpts.DestinationOptions = diskOpts;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
report.Export();
// write the pdf file to the Client browser
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(FName);
Response.Flush();
Response.Close();
// delete the exported file from the disk
System.IO.File.Delete(FName);
}
}
}
|

April 7th, 2007, 12:28 AM
|
|
Registered User
|
|
Join Date: Apr 2007
Location: Peshawar, , Pakistan.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi friend.
It may seem very late.
i have some suggested solution for your problem.
Make two datasets, one for the main report and the other for the subreprot.
populate both.
and then do as follows.
MyMainReport report = new MyMainReport();
report.SetDataSource(firstDataSet);
report.OpenSubReport(nameOfTheSubReport).SetDataSo urce(secondDataSet);
I've not tried it yet, but hope it will work.
good luck.
Right is might.
|

August 24th, 2008, 05:42 AM
|
|
Registered User
|
|
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Though it is so late reply but sharing knowlwdge shouldn't be time dependent :)
Note:-
Assume that GetMainResult() and GetChangeState() return typed DataSet containng two tables "MainTableRecord" and "MainTableSubReportRecord" through which you have drop the field in your Reports.And also you bind subreport with the field which is common among MainTableRecord and MainTableSubReportRecord.
SOLUTION:
By this solution you will have a basic idea how to work with subReports in Crystal Report using C#.
ReportDocument customerReport = new ReportDocument();
customerReport.Load("D:\\MYWEBSITE\REPORTS\MainRep ort.rpt);
DataSet2 dsResult = rptMgr.GetMainResult();
DataSet2 dsSubReportResult = rptMgr.GetChangeState();
customerReport.SetDataSource(dsResult.Tables["MainTableRecord"]);
customerReport.OpenSubreport("MainSubReport.rpt"). SetDataSource(dsSubReportResult.Tables["MainTableSubReportRecord"]); ;
CrystalReportViewer1.Visible = true;
CrystalReportViewer1.ReportSource = customerReport;
CrystalReportViewer1.DataBind();
|

April 16th, 2009, 07:20 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
C# crystal reports subreport
|

October 8th, 2009, 06:36 AM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ReportDocument customerReport = new ReportDocument();
customerReport.Load("D:\\MYWEBSITE\REPORTS\MainRep ort.rpt);
DataSet2 dsResult = rptMgr.GetMainResult();
DataSet2 dsSubReportResult = rptMgr.GetChangeState();
customerReport.SetDataSource(dsResult.Tables["MainTableRecord"]);
customerReport.OpenSubreport("MainSubReport.rpt"). SetDataSource(dsSubReportResult.Tables["MainTableSubReportRecord"]); ;
CrystalReportViewer1.Visible = true;
CrystalReportViewer1.ReportSource = customerReport;
CrystalReportViewer1.DataBind();
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
These code work only for main report..main report display result..but sub report not show recods..pls help me.i want to display main report & sub report details.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |