Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good Day,

PROBLEM # 1
I tried populating my crystalreport programatically using code below.
VB
Imports MySql.Data.MySqlClient

DIM obj_masterfile As New rpt_masterfile

public sub populate_data()

Dim da As New MySqlDataAdapter
                da = New MySqlDataAdapter("select * from v_masterfile", cn)
                Dim tbl_new As New DataTable
                da.Fill(tbl_new)
                obj_masterfile.SetDataSource(tbl_new)
                frm_reports.Show()
                frm_reports.CrystalReportViewer1.ReportSource = obj_masterfile

end sub

Table Name: v_masterfile
HTML
Emp_name          Emp_age
Jay                 21
John                23
Jayson              21
Jonny               24

This works great, however when i press the refresh button in crystalreportviewer it doesn't show any changes when i edit data at the backend.


PROBLEM # 2
For some reasons i don't want to populate my crystalreport via ODBC(RDO) so i used ADO.NET instead, based on the Data Source i initialized (shft + alt + D).

On Report Design > Database expert > Project Data> ADO.NET DataSets > v_masterfile

Then dragging emp_ name and emp_age on my report designer

The problem here is when i run the program reports does not shows any records.


NOTE: I tried using ODBC and it works, but i need not to use ODBC because this will be a client software that will use dynamic connection strings.

Thank you for reading.
Posted
Updated 3-Apr-17 21:56pm
v3

1 solution

Problem 1

The data is not refreshed because the report still use the old datasource which was not refreshed. You should be able to get it by doing select again at the report refresh event.

VB
Private Sub CRViewer_ReportRefresh(ByVal source As Object, ByVal e As CrystalDecisions.Windows.Forms.ViewerEventArgs) Handles CRViewer.ReportRefresh
        populate_data()
End Sub

Public Sub populate_data()
        Dim da As New MySqlDataAdapter("select * from v_masterfile", cn)
        Dim tbl_new As New DataTable
        da.Fill(tbl_new)
        obj_masterfile.SetDataSource(tbl_new)
End Sub


I didn't try the code myself so adjust accordingly.

Problem 2

Well since you're getting the data programmatically then if you want to use different connection then you should be doing it at the connection initialization instead of at the report itself (before querying the database to get data).

What matter is the report got the datasource it requires and it would work like you have designed it.
 
Share this answer
 
v2
Comments
JMAM 13-May-13 22:30pm    
On Problem # 2, I didn't get DATA programatically,

NOTE: I created a DATASOURCE on design time(shft + alt + D).

Then on CRYSTAL REPORT design time, i use Database expert > Project Data> ADO.NET DataSets > v_masterfile


The problem is when i run the program report does not show any record.

Addtionally i created another dataosource using ODBC wondering if i will have different results. Then on CRYSTAL REPORT design time, i use Database expert > Project Data> ADO.NET DataSets > v_masterfile

When i run my program this time using ODBC it shows good records compared to ADO.NET on design time that shows no record at all.
Ezra Neil 13-May-13 23:39pm    
What I can infer from your code and explanation, you're using MySQL .Net connector connecting to MySQL database right?

If you Grid is displaying data properly from DataSet then there is no problem with DataSource.

Use the typed dataset to design report. Go to Field Explorer > Add/Remove DataSet > ADO.NET (XML) browse to your dataset file and finish.Now all the tables that you created in typed dataset will be visible in report, now design report using them.

Make sure the dataset you are setting to the datasouce has the same dataset name as the name of your typed dataset and also the same structure.

If that still doesnt make it work then post more of your code. Maybe we can find something from there.
JMAM 18-May-13 15:49pm    
Hello,

Actually i just re installed my Visual Studio 2008, MySQL .Net Connector & MySQL v5.1.53
Thinking that it might be the configuration. Thus

I created a new project, With form1 i added crystal report viewer, from crystal report viewer i select create a blank report file. Thus i added a new Datasoure, select MySQL, entered necessary connection details such as server host = Localhost, User ID= root, Password = 3 then

Finally from the crystal report file Field Explorer, I click database Expert, Select ADO.NET from Project data then drag any database table then drag a few fields going to report row details. then i executed the program. Then Still no data is being showed. However when i use Microsoft report viewer, then create a report then get data from ado.net also, then i can see info when i run the application.

i am so devastated with this error now. This is my first time to encounter this. Before i can do it without any errors.


Additionally you may download my sample project, including DB, connector and other details so you may see why error actually happens and impossible for me to trace.

https://dl.dropboxusercontent.com/u/65392916/SAMPLE.rar
JMAM 18-May-13 15:51pm    
BTW, I would like to thank you for helping me

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



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