Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
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
Posted

1 solution

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
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900