Answered by:
Crystal report with multiple Datasource

Question
-
User939426669 posted
Hi,
I am trying to create a report using crystal report 11 and asp.net 2.0(C#) and Oracle10g.
My requirement is to create a report which contains 6 pages with each pages different and is connected to different datasource. I pass three parameter (1)USER_ID, (II)YEAR and (III)TYPE. Based on these parament i'd like to construct a report with different layout on different pages with different datasource.
Can i do it in single .rpt file or do i need to nested with sub reports. I am trying to create 6 subreports with their own datasource and put it in one parent report to display data, but not able to do it.
Please suggest me your valuable comments.
Thanks.
Wednesday, January 19, 2011 2:22 PM
Answers
-
User939426669 posted
private void test_report() { string strReportPath = Server.MapPath("~\\Report\\OverallReport.rpt"); objRpt.Load(strReportPath); // Create Main Report DataTable DataTable vDT = new DataTable(); DataColumn No = vDT.Columns.Add("No", typeof(System.String)); DataColumn Rating = vDT.Columns.Add("Rating", typeof(System.String)); DataColumn Value = vDT.Columns.Add("Value", typeof(System.Int16)); DataColumn Weight = vDT.Columns.Add("Weight", typeof(System.String)); DataColumn TotalValue = vDT.Columns.Add("TotalValue", typeof(System.Int16)); vDT.Rows.Add("TEST 1", "TEST 2", 1, "TEST 3", 100); // Test Data // End Creating LE DataTable objRpt.SetDataSource(vDT); // Create subReport DataTable DataTable _vDT = new DataTable(); DataColumn _No = _vDT.Columns.Add("No", typeof(System.String)); DataColumn _Rating = _vDT.Columns.Add("Rating", typeof(System.String)); DataColumn _Value = _vDT.Columns.Add("Value", typeof(System.Int16)); DataColumn _Weight = _vDT.Columns.Add("Weight", typeof(System.Int16)); DataColumn _TotalValue = _vDT.Columns.Add("TotalValue", typeof(System.Int16)); _vDT.Rows.Add("SUBREPORT", "SUBREPORT",100,100,1000); // end creating virtual dataTable
objRpt.Subreports["subReport.rpt"].SetDataSource(_vDT); CrystalReportViewer1.ReportSource = objRpt; CrystalReportViewer1.DisplayToolbar = true; CrystalReportViewer1.HasPrintButton = true; CrystalReportViewer1.HasExportButton = true; }
Thanks for your reply.I tried following you code. But couldn't go through further because of this error.
System.NullReferenceException: Object reference not set to an instance of an object.
I put the correct name of the subreport and bind it to dataTable, but still showing null exception.
Here's the code. Please let me know where i am wrong.
Also. I put my subreport inside Detail Section of Main Report. Do i need to place in any other sections of the report?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 24, 2011 5:16 PM
All replies
-
User-1923420989 posted
you can do it in single .rpt file which has one main report and number of sub reports nested.
have a look at my code how i am supplying different dataset as different data sources for the main report and sub reports...
Dim iInvoiceNo As Integer iInvoiceNo = CType(Request.QueryString("InvoiceNo"), Integer) Dim Disport As New ReportDocument Disport.Load(Server.MapPath("../Accounts forms/Reports/InvoicePreview.rpt")) Disport.SetDataSource(InvoiceManager.PrintInvoice(iInvoiceNo)) Disport.OpenSubreport("InvAdds").SetDataSource(InvoiceAdditionsManager.PrintInvoiceAdditions(iInvoiceNo).Tables(0)) Disport.OpenSubreport("InvDeds").SetDataSource(InvoiceDeductionsManager.PrintInvoiceDeductions(iInvoiceNo).Tables(0)) CrvInvoice.ReportSource = Disport CrvInvoice.DisplayToolbar = True CrvInvoice.HasPrintButton = True CrvInvoice.HasExportButton = True
it is the working code.. let me know if you need my further assistance...Monday, January 24, 2011 4:46 AM -
User939426669 posted
private void test_report() { string strReportPath = Server.MapPath("~\\Report\\OverallReport.rpt"); objRpt.Load(strReportPath); // Create Main Report DataTable DataTable vDT = new DataTable(); DataColumn No = vDT.Columns.Add("No", typeof(System.String)); DataColumn Rating = vDT.Columns.Add("Rating", typeof(System.String)); DataColumn Value = vDT.Columns.Add("Value", typeof(System.Int16)); DataColumn Weight = vDT.Columns.Add("Weight", typeof(System.String)); DataColumn TotalValue = vDT.Columns.Add("TotalValue", typeof(System.Int16)); vDT.Rows.Add("TEST 1", "TEST 2", 1, "TEST 3", 100); // Test Data // End Creating LE DataTable objRpt.SetDataSource(vDT); // Create subReport DataTable DataTable _vDT = new DataTable(); DataColumn _No = _vDT.Columns.Add("No", typeof(System.String)); DataColumn _Rating = _vDT.Columns.Add("Rating", typeof(System.String)); DataColumn _Value = _vDT.Columns.Add("Value", typeof(System.Int16)); DataColumn _Weight = _vDT.Columns.Add("Weight", typeof(System.Int16)); DataColumn _TotalValue = _vDT.Columns.Add("TotalValue", typeof(System.Int16)); _vDT.Rows.Add("SUBREPORT", "SUBREPORT",100,100,1000); // end creating virtual dataTable
objRpt.Subreports["subReport.rpt"].SetDataSource(_vDT); CrystalReportViewer1.ReportSource = objRpt; CrystalReportViewer1.DisplayToolbar = true; CrystalReportViewer1.HasPrintButton = true; CrystalReportViewer1.HasExportButton = true; }
Thanks for your reply.I tried following you code. But couldn't go through further because of this error.
System.NullReferenceException: Object reference not set to an instance of an object.
I put the correct name of the subreport and bind it to dataTable, but still showing null exception.
Here's the code. Please let me know where i am wrong.
Also. I put my subreport inside Detail Section of Main Report. Do i need to place in any other sections of the report?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 24, 2011 5:16 PM -
User2092358858 posted
Thanks...after a week of searching how to do this your solution worked for me!
Friday, August 26, 2011 10:12 AM