Click here to Skip to main content
13,553,262 members
Rate this:
Please Sign up or sign in to vote.
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.


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


Posted 13-Jan-13 7:39am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
        '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

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

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

End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180515.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100