How to Display data from MySQL to Crystal Report
How to Display data from MySQL to Crystal Report –
In this tutorial you’ll learn how to display data from mysql to crystal report. In this tutorial you’ll see how to fetch data from single table and from multiple table. So Let’s start the tutorial…
1. Here you will see how to fetch data from single table and multiple tables.
2. Before we start these tutorial, we need to understand some points i.e. –
i. Visual Studio 2010, 2012, 2013 and 2015 you have to download crystal report.
ii. Crystal Report download from this site
iii. After downloading, install it.
3. After installing, start the visual studio and create new project and select 4.0 .Net framework because crystal report works on 4.0 framework.
4. Before creating crystal report you need to create data source. For that first install MySQL ODBC 3.51 32 bit or 64 bit Driver according your system requirement.
5. After installing MySQL ODBC Driver, you need to create Data Source for crystal report for these follow the following steps –
i. First go to the Control Panel.
ii. Then select Administrative Tools.
iii. In Administrative Tools, select ODBC Data Source.
iv. After selecting ODBC Data Source, one window will open. On the right side of the window you’ll see Add Button. Click on the Add Button one more window will open.
v. In that window search the MySQL ODBC Driver and select it and click on the Finish button. After that MySQL Connector/ODBC Data Source Configuration window will open.
vi. In first text box give data source according your requirement and in the TCP/IP server type localhost and in the user type root. If ant username you have given to your database then write that name and at last select the database and click on Ok button.
vii. Your data source is now ready.
6. Now create a new form. In the tool box, click on the Reporting menu and click on CrystalReportViewer and drag it to the form.
7. Then click on the project, click on the Add New Item, click on the Reporting section, Crystal Reports will appear. Click on the crystal report.
8. Then Crystal Report Gallery will open. Select Using the Report Wizard and Choose Standard Expert.
9. After that Standard Report Creation Wizard window will open. In that available data source, click on the Create New Connection, click on the ODBC(RDO) and select data source which you have created.
10. Then select My Connections your created data source will appear. Select the data source and click on the data source and select the table which you required. After that click on next button and select the required fields then click on finish.
11. Selected fields will appear on the crystal report.
12. For the single table given code will be use –
13. Sometimes one error will generated while running the crystal report. The error it may be crystal report is not running. For that go to the app.config to your project and you’ll see the configuration tag. Inside the configuration tag, startup tag will available. In the startup tag write this code –
14. You have to write this code in the startup opening tag. Your error will resolve.
15. Output –
16. Above code is used for single table and for multiple table given code will be use. While selecting the tables from data source, select the one or more table.
17. Output –