1

早上好,

在观看了大量在线教程并阅读了文档后,我决定开始使用 Crystal Reports for Visual Studio 运行时。据我了解,SAP Crystal Reports 运行时本身并不支持与 MySQL 数据库的连接,因此我相信我已正确完成所有操作,将数据库记录拉入 Dataset 对象。我可以看到数据集中的记录,它们与数据库中的记录相匹配。不幸的是,当我运行报告的预览时,除了日期字段之外,所有内容都是“乱码”。

我很困惑,不知道现在该怎么办,任何帮助将不胜感激。下面的屏幕截图显示了数据集中的记录以及报告预览。

顺便说一句,服务器和表上的排序规则都设置为“ Latin1 - 默认排序规则” - 不确定这是否有任何区别。

图片 #1:查看数据集记录

在此处输入图像描述 点击此处查看大图: https ://dl.dropbox.com/u/55174425/Dataset%20Records.jpg

图片 #2:报告的设计视图

在此处输入图像描述 点击此处查看大图: https ://dl.dropbox.com/u/55174425/Design%20View%20of%20Report.jpg

图片#3:报告预览

在此处输入图像描述 点击这里查看大图: https ://dl.dropbox.com/u/55174425/Preview%20of%20Report.jpg

4

1 回答 1

3

你好,

我设法回答了我自己的问题,并决定分享我的答案,以防有人遇到同样的问题。

好吧,这不是什么大问题,因为它是 Crystal Reports for Visual Studio 运行时的实际工作方式(至少在涉及 MySQL 时)。我没有意识到的是,因为 VS 的 CR 运行时不支持与 MySQL 数据库的本机连接,所以有必要使用 Visual Studio 使用 .Net 连接器创建服务器连接(当您安装连接器)。

建立服务器连接后,我就可以创建一个 DataSet 并使用数据库中的记录填充它。不幸的是,我没有意识到这个数据集只允许选择设计报告(.rpt 文件)所需的字段/列。现在,这就是我的“胡言乱语”问题所在。事实上,我发现 CR 运行时在您设计报告时故意使用随机文本/字符,如果您预览报告,您会看到这一点。此外,如果您调试应用程序,您将得到一个只有列标题的空白报告。

对此的解决方案是以编程方式查询数据库、创建和填充 DataTable 并将其分配给您刚刚创建的报表的新实例作为其数据源。还有中提琴,报告现在显示了我正在寻找的信息。因此,这是我在运行时最终使用的代码,以便让我的报告显示我正在寻找的数据:

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
        'Define the MySQL Connection String.
        Dim myConnectionString As String = "Server=server_address;Port=3306;Uid=user_id;Password=password;Database=schema_name;"

        'Create a new MySqlConnection object and assign the Connection String to it.
        Dim dbConn As New MySqlConnection(myConnectionString)

        'Define your Query.
        Dim dbQuery As String = "SELECT * FROM users"

        'Create a new MySqlDataAdapter object and assign the Query and Connection String objects to it.
        Dim dbAdapter As New MySqlDataAdapter(dbQuery, dbConn)

        'Create a new DataTable object and fill it with the contents of the MySqlDataAdapter object.
        Dim dbTable As New DataTable
        dbAdapter.Fill(dbTable)

        'Create a new instance of the report you previously designed and set its DataSource to the DataTable.
        Dim report As New rptUserList
        report.SetDataSource(dbTable)

        'Set the ReportSource of the CrystalReportViewer control to your report.
        CrystalReportViewer1.ReportSource = report
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
于 2013-01-14T22:00:50.740 回答