gpt4 book ai didi

asp.net - Crystal Report 仅显示第一页

转载 作者:行者123 更新时间:2023-12-01 05:06:37 27 4
gpt4 key购买 nike

我正在使用 ASP.NET 、 SQL 、 Crystal Report。我已成功生成单页报告。但是当报表大小超过一页时,Crystal Report 只显示第一页数据。当我单击下一步按钮时,它会显示“源为空或找不到源”之类的消息。

  Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim rptDoc As New ReportDocument
Dim ds As New StudentDataSet
Dim sqlCon As SqlConnection
Dim dt As New DataTable
dt.TableName = "Crystal Report Example"
sqlCon = New SqlConnection(myCon)
Dim da As New SqlDataAdapter("select * from tblStudent", sqlCon)
da.Fill(dt)
ds.Tables(0).Merge(dt)
rptDoc.Load(Server.MapPath("~\Reports\StudentList.rpt"))
rptDoc.SetDataSource(ds)
CrystalReportViewer1.ReportSource = rptDoc

End Sub

enter image description here

最佳答案

加载报告的代码必须在每次回发时执行 .
Page_Init 是放置此代码的正确位置(Page_Load 可能会导致一些错误)。

试试这个改变(对不起 VB 错误,我使用 C#):

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ButtonClicked = true
ShowReport()

Protected void Page_Init(object sender, EventArgs e)
ShowReport()

Protected Sub ShowReport()
Dim rptDoc As New ReportDocument
Dim ds As New StudentDataSet
Dim sqlCon As SqlConnection
Dim dt As New DataTable
dt.TableName = "Crystal Report Example"
sqlCon = New SqlConnection(myCon)
Dim da As New SqlDataAdapter("select * from tblStudent", sqlCon)
da.Fill(dt)
ds.Tables(0).Merge(dt)
rptDoc.Load(Server.MapPath("~\Reports\StudentList.rpt"))
rptDoc.SetDataSource(ds)
CrystalReportViewer1.ReportSource = rptDoc

End Sub

嘿嘿,建议每次卸载页面都关闭ReportDocument;这避免了报告计数器的不受控制的增加,这将停止应用程序
protected void Page_Unload(object sender, EventArgs e)
{
if (reportDocument != null)
reportDocument.Close();
}

关于asp.net - Crystal Report 仅显示第一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27916070/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com