Crystal Report未显示SQL Server 17.5中的数据

时间:2018-06-12 03:16:50

标签: sql-server vb.net crystal-reports

创建表并在上一个表单中放入数据后,此表单会尝试显示报表,但我收到一个空白报表。我做错了什么?

以下是表单加载事件的VB 2017代码:

Imports CrystalDecisions.CrystalReports.Engine
Public Class Form5
    Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim cryRpt As New ReportDocument
        cryRpt.Load("C:\Users\Administrator\source\repos\WindowsApp3\WindowsApp3\CrystalReport4.rpt")
        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

我通过以下方式解决了我的问题

这是我修改的表单加载事件的VB 2017代码:

    Dim query As String = "SELECT * FROM monAtt"
    Dim cmd As New SqlCommand(query, conn1)
    cmd.CommandType = CommandType.Text

    conn1.Open()
    Dim MyDA As New SqlClient.SqlDataAdapter()
    MyDA.SelectCommand = cmd
    Dim myDS As New TestDataSet1()
    MyDA.Fill(myDS, "monAtt")
    Dim oRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
    oRpt.Load("C:\Users\Administrator\source\repos\WindowsApp3\WindowsApp3\CrystalReport4.rpt")
    oRpt.SetDataSource(myDS.Tables("monAtt"))
    CrystalReportViewer1.ReportSource = oRpt
    CrystalReportViewer1.RefreshReport()
    CrystalReportViewer1.Visible = True
    conn1.Close()
    cmd.Dispose()