Create a new ODBC (RDO) connection for the .rpt file and proceed to the next step.
Instead of a DSN connection, enter the connection string and click Next.
Driver={MySQL ODBC 8.0 UNICODE Driver};Server=<server_name>;Database=<database_name>;Uid=<database_user_name>;Password=<database_password>
Enter all the required database information and click Finish.
In your application code, you can use the following:
For System.Data.Odbc.OdbcConnection:
string connectionString = "Driver={MySQL ODBC 8.0 UNICODE Driver};Server=<server_name>;Database=<database_name>;Uid=<database_user_name>;Password=<database_password>";
string queryText = "<your_sql_query>";
OdbcConnection connection = new OdbcConnection(connectionString);
try
{
connection.Open();
OdbcCommand command = new OdbcCommand(queryText, connection);
OdbcDataAdapter adapter = new OdbcDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, "your_table_data");
ReportDocument report = new ReportDocument();
report.Load("<your_.rpt_file_path>");
report.SetDataSource(dataSet);
CrystalReportViewer1.ReportSource = report;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
connection.Close();
}
For MySql.Data.MySqlClient.MySqlConnection:
string connectionString = "Server=<server_name>;Database=<database_name>;Uid=<database_user_name>;Password=<database_password>";
string queryText = "<your_sql_query>";
MySqlConnection connection = new MySqlConnection(connectionString);
try
{
connection.Open();
MySqlCommand command = new MySqlCommand(queryText, connection);
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, "your_table_data");
ReportDocument report = new ReportDocument();
report.Load("<your_.rpt_file_path>");
report.SetDataSource(dataSet);
CrystalReportViewer1.ReportSource = report;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
connection.Close();
}
Article ID: 2277, Created: March 15 at 11:44 PM, Modified: March 15 at 11:47 PM