I want to create crystal report in c# with mysql.please help me by providing the procedure.

Dani AI

Generated

— the most reliable pattern is to design the .rpt against a typed ADO.NET DataSet and then fill that DataSet at runtime from MySQL. That avoids the common "database logon" headaches and works the same if you want to use SQL Server (as asked) — just swap the ADO.NET provider. ’s prompt to ask “what have you tried” is exactly right: the steps below assume you start with no working report and want to do it in code.

  1. Install Crystal Reports for Visual Studio and the Crystal runtime you will deploy.
  2. Install MySQL Connector/NET and add a reference to MySql.Data.dll (for SQL Server use System.Data.SqlClient).
  3. Add a typed DataSet (.xsd) to the project and define the table/columns your report needs.
  4. Create the Crystal Report (.rpt) using “Project Data -> ADO.NET DataSets” and base it on that typed DataSet.
  5. Put a CrystalReportViewer on your form/page. At runtime fill the DataSet, load the .rpt and call SetDataSource.

A minimal ASP.NET example (MySQL) — replace connection/provider for SQL Server:

using MySql.Data.MySqlClient;
using CrystalDecisions.CrystalReports.Engine;

var rpt = new ReportDocument();
rpt.Load(Server.MapPath("~/Reports/MyReport.rpt"));

var ds = new DataSet();
using (var cn = new MySqlConnection("Server=host;Database=db;Uid=user;Pwd=pwd;"))
using (var da = new MySqlDataAdapter("SELECT * FROM MyTable", cn))
{
    da.Fill(ds, "MyTable");
}

rpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = rpt;

Notes and troubleshooting: set project platform to x86 (CR runtimes are commonly 32-bit), install the matching Crystal runtime on the server, ensure the typed DataSet schema matches the filled DataTable names, and always call Close/Dispose on ReportDocument to avoid leaks. If a report was designed against a direct DB connection you can either rebind it to a DataSet or use SetDatabaseLogon/ConnectionInfo for each table, but the typed DataSet approach is usually simpler and more robust.

Recommended Answers

All 2 Replies

What have you tried so far?

Hi there, I have also the same problem But i m using SQLServer 2005. I have created Crystal Reports using wizards only but i want to do it throuth coding.
I just have added a report form to my project. Wt to do next i dont know.
Plz help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.