早上好
在观看了大量在线教程并阅读了文档之后,我决定开始使用 Crystal Reports for Visual Studio 运行时。据我了解,SAP Crystal Reports 运行时本身不支持与 MySQL 数据库的连接,因此我相信我已经正确地完成了将数据库记录拉入数据集对象的所有操作。我可以看到数据集中的记录,它们与数据库中的记录相匹配。不幸的是,当我运行报表预览时,除日期字段外,所有内容都是“乱码”。
我很困惑,现在不知道该怎么办,如果有任何帮助,我们将不胜感激。下面的屏幕截图显示了数据集中的记录以及报告预览。
顺便说一句,服务器和表上的排序规则都设置为“Latin1 - 默认排序规则”——不确定这是否有任何区别。
图像 #1:数据集记录 View
单击此处查看大图:https://dl.dropbox.com/u/55174425/Dataset%20Records.jpg
图像 #2:报告的设计 View
单击此处查看大图:https://dl.dropbox.com/u/55174425/Design%20View%20of%20Report.jpg
图片 #3:报告预览
单击此处查看大图:https://dl.dropbox.com/u/55174425/Preview%20of%20Report.jpg
最佳答案
你好,
我设法回答了我自己的问题,并决定分享我的答案,以防有人遇到同样的问题。
好吧,这不是什么大问题,因为它是 Crystal Reports for Visual Studio 运行时的实际工作方式(至少在涉及 MySQL 时)。我没有意识到的是,因为 VS 的 CR 运行时不支持与 MySQL 数据库的 native 连接,所以有必要使用 Visual Studio 使用 .Net 连接器创建服务器连接(当您安装连接器)。
建立服务器连接后,我便可以创建数据集并使用数据库中的记录填充它。不幸的是,我没有意识到这个数据集只允许选择设计报告(.rpt 文件)所需的字段/列。现在,这就是我的“乱码”问题所在。事实上,我发现当您设计报告时,CR 运行时有意使用随机文本/字符,如果您预览报告,您会看到这一点。此外,如果您调试应用程序,您将得到一个只有列标题的空白报告。
此问题的解决方案是以编程方式查询数据库,创建并填充数据表并将其分配给您刚刚创建的报表的新实例作为其数据源。中提琴,报告现在显示了我正在寻找的信息。因此,这是我最终在运行时使用的代码,目的是让我的报告显示我正在寻找的数据:
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
关于mysql - 什么可能导致 Visual Studio 2010 中的 Crystal Report 显示乱码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14291095/