Click here to Skip to main content
Rate this: bad
good
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.
 
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 13-Jan-13 7:39am

1 solution

Rate this: bad
good
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
        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
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 494
1 CPallini 325
2 OriginalGriff 225
3 George Jonsson 130
4 ChauhanAjay 104
0 OriginalGriff 6,464
1 Sergey Alexandrovich Kryukov 5,915
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
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