问题描述
我在显示带有 2 个子报表的水晶报表时遇到问题.两个子报表都从存储过程中提取数据.
在设计时一切正常.但是在运行时,Crystal Reports 出现错误,提示未找到表(第二个表)并且报告中未显示任何内容.
这是我想解决的类似问题-
这就是我打开子报表的方式.
Dim mainReport As <带有crpt扩展名的报告名称>Dim subReport As CrystalDecisions.CrystalReports.Engine.ReportDocumentDim subReport2 作为 CrystalDecisions.CrystalReports.Engine.ReportDocumentsubReport = mainReport.OpenSubReport()subReport2 = mainReport.OpenSubReport()mainReport.SetDataSource(<你的主报表的数据表>)subReport.SetDataSource(<你的数据表>)subReport2.SetDataSource()reportViewer.ReportSource = mainReport
或来自您的代码
将 rptDoc 改成新的 rptDailyCashReportDim subReport1 作为 CrystalDecisions.CrystalReports.Engine.ReportDocumentDim subReport2 作为 CrystalDecisions.CrystalReports.Engine.ReportDocumentsubReport1 = rptDoc.OpenSubReport() ')subReport1.SetDataSource(DS.Tables(0))subReport2.SetDataSource(DS.Tables(1))' 把它放在最后一部分,然后显示你的报告rptDoc.DataDefinition.FormulaFields("SchoolName").Text = "'" &持有学校名称 &'"rptDoc.SetParameterValue("@FDate", DOF)Dim objForm 作为新的 ShowReportobjForm.ViewReport(rptDoc, , "")objForm.ShowDialog()
I have facing problem while showing crystal report with 2 subreports. Both subreports pulling data from stored procedure.
All working fine on design time. But at runtime, Crystal Reports has an error saying table not found (second table) and nothing is displayed in reports.
This is the similar problem that I want to solve -Crystal Report for Income and Expense wth opening and closing balance
This is my code - both stored procedure has a single parameter of datetime
type:
Dim DOF As Date = #4/1/2016#
DOF = Format(DOF, "dd/MM/yyyy")
Dim DOT As Date = #4/1/2016# ' Now.Date
DOT = Format(DOT, "dd/MM/yyyy")
Dim DS As Data.DataSet
Dim DA As SqlDataAdapter
Dim s_Sql As String
Dim s_sql2 As String
Dim cmd As SqlCommand
s_Sql = "sp_DailyIncome"
cmd = New SqlCommand(s_Sql, o_con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@FDate", Format(DOF, "MM/dd/yyyy")))
DA = New SqlDataAdapter
DA.SelectCommand = cmd
DS = New Data.DataSet
DA.Fill(DS, s_Sql)
cmd.Dispose()
s_sql2 = "sp_DailyExpense"
o_Cmd = New SqlCommand(s_sql2, o_con)
o_Cmd.CommandType = CommandType.StoredProcedure
o_Cmd.Parameters.Add(New SqlParameter("@FDate", Format(DOF, "MM/dd/yyyy")))
DA.SelectCommand = o_Cmd
DA.Fill(DS, s_sql2)
Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
rptDoc = New rptDailyCashReport
rptDoc.DataDefinition.FormulaFields("SchoolName").Text = "'" & holdSchoolName & "'"
rptDoc.SetParameterValue("@FDate", DOF)
rptDoc.Subreports.Item(0).SetDataSource(DS.Tables(0))
rptDoc.Subreports.Item(1).SetDataSource(DS.Tables(1))
Dim objForm As New ShowReport
objForm.ViewReport(rptDoc, , "")
objForm.ShowDialog()
and this is the error:
this is how I open a subreport.
Dim mainReport As <Name of your report with crpt extension>
Dim subReport As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim subReport2 As CrystalDecisions.CrystalReports.Engine.ReportDocument
subReport = mainReport.OpenSubReport(<name of your subreport as defined in your main report>)
subReport2 = mainReport.OpenSubReport(<name of your second subreport as defined in your main report>)
mainReport.SetDataSource(<your main report's datatable>)
subReport.SetDataSource(<your datatable>)
subReport2.SetDataSource(<your datatable 2>)
reportViewer.ReportSource = mainReport
or from your code
Dim rptDoc As New rptDailyCashReport
Dim subReport1 As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim subReport2 As CrystalDecisions.CrystalReports.Engine.ReportDocument
subReport1 = rptDoc.OpenSubReport(<name of your sub report 1>) '<-- !! NAME IS CASE SENSITIVE
subReport2 = rptDoc.OpenSubReport(<name of your second sub report>)
subReport1.SetDataSource(DS.Tables(0))
subReport2.SetDataSource(DS.Tables(1))
' place this at the last part, before showing your report
rptDoc.DataDefinition.FormulaFields("SchoolName").Text = "'" & holdSchoolName & "'"
rptDoc.SetParameterValue("@FDate", DOF)
Dim objForm As New ShowReport
objForm.ViewReport(rptDoc, , "")
objForm.ShowDialog()
这篇关于以编程方式为子报表 VB.net 添加多个数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!