什么可能导致Visual Studio 2010中的Crystal报表显示“胡言乱语”? [英] What Could Be Causing Crystal Report in Visual Studio 2010 To Display "Gibberish"?

查看:78
本文介绍了什么可能导致Visual Studio 2010中的Crystal报表显示“胡言乱语”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,



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



我很难过,现在不知道该怎么做,我们将非常感谢任何帮助。下面的屏幕截图显示了数据集中的记录以及报告预览。



截图#1:数据记录视图

截图#2报告的设计视图

截图$ 3预览报告



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



谢谢。



// Kismet

解决方案

3预览报告



顺便说一下,整理在服务器和表上都设置为 Latin1 - Default Collat​​ion - 不确定是否有任何区别。



谢谢。< br $> b $ b

// Kismet


大家好,



我设法回答了我自己的问题并决定分享我的答案以防有人在那里跑同样的问题。



嗯,这不是一个问题,因为它是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
''定义MySQL连接字符串。
Dim myConnectionString As String =Server = server_address; Port = 3306; Uid = user_id; Password = password; Database = schema_name;

''创建一个新的MySqlConnection对象并为其分配连接字符串。
Dim dbConn As New MySqlConnection(myConnectionString)

''定义查询。
Dim dbQuery As String =SELECT * FROM users

''创建一个新的MySqlDataAdapter对象并为其分配Query和Connection String对象。
Dim dbAdapter As New MySqlDataAdapter(dbQuery,dbConn)

''创建一个新的DataTable对象并用MySqlDataAdapter对象的内容填充它。
Dim dbTable As New DataTable
dbAdapter.Fill(dbTable)

''创建您之前设计的报告的新实例,并将其DataSource设置为DataTable。
Dim report As New rptUserList
report.SetDataSource(dbTable)

''将CrystalReportViewer控件的ReportSource设置为您的报表。
CrystalReportViewer1.ReportSource =报告
Catch ex As Exception
MsgBox(ex.Message)
结束尝试

结束子


Good-day All,

After watching numerous online tutorials and reading the documentation, I decided to get hands on with the Crystal Reports for Visual Studio runtime. It is my understanding that the SAP Crystal Reports runtime doesn''t natively support connections to a MySQL DB so I believe I''ve done everything correctly to pull the DB records into a Dataset object. I can see the records in the Dataset and they match what''s in the Database. Unfortunately, when I run a preview of the report everything is "gibberish" except for the Date fields. Also, at run-time the report is blank.

I''m stumped and don''t know what to do now, any assistance would be greatly appreciated. Screenshots below show the records from the Dataset as well as the Report preview.

Screenshot #1: VIEW OF DATASET RECORDS
Screenshot #2 DESIGN VIEW OF REPORT
Screenshot $3 PREVIEW OF REPORT

By the way, the Collation on the server and table are both set to "Latin1 - Default Collation" - not sure if that makes any difference.

Thanks.

//Kismet

解决方案

3 PREVIEW OF REPORT

By the way, the Collation on the server and table are both set to "Latin1 - Default Collation" - not sure if that makes any difference.

Thanks.

//Kismet


Hi all,

I managed to answer my own question and decided to share my answer in case somebody out there runs into this same problem.

Well, it''s not so much a problem as it is the actual way the Crystal Reports for Visual Studio runtime is supposed to work (at least when it comes to MySQL). What I didn''t realize was that, because the CR runtime for VS didn''t support a native connection to a MySQL database, it was necessary to use Visual Studio to create a Server Connection using the .Net Connector (which is made available when you install the Connector).

Once the server connection was made, I was then able to create a DataSet and populate it with the records from the DB. Unfortunately, what I didn''t realize was that this dataset simply allows for the selection of the fields/columns necessary for the designing of the report (.rpt file). Now, here''s where my "gibberish" problem was. In fact, I discovered that the CR runtime purposefully uses random text/characters when you''re designing the report and if you preview the report you will see this. Also, if you debug the application you will get a blank report with only the column headers.

The solution to this is to programatically query the DB, create and fill a DataTable and assign it to a new instance of the report you just created as its datasource. And viola, the report now shows the information I was looking for. So, here''s the code I ended up using at run-time in order to get my report to display the data I was looking for:

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


这篇关于什么可能导致Visual Studio 2010中的Crystal报表显示“胡言乱语”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆