我想使用Mysql数据库在我的报告中显示数据,首先,我使用MYSQL命令创建了一个数据表,如下所示:
public static DataTable getResults(string _reqSelect, string _tableName, int _id_usr)
{
string serverIp = "localhost";
string username = "root";
string password = "";
string databaseName = "labo";
string conString = string.Format("server={0};uid={1};pwd={2};database={3};", serverIp, username, password, databaseName);
MySqlConnection con = new MySqlConnection(conString);
DataSet daSet1 = new DataSet();
DataTable daTable1 = new DataTable();
try
{
MySqlCommand cmd;
con.Open();
cmd = new MySqlCommand(_reqSelect, con);
//cmd.Parameters.AddWithValue("@dt_cre", dt_cre);
//cmd.Parameters.AddWithValue("@id_societe", _id_societe);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
adapter.Fill(daSet1, _tableName);
daTable1 = daSet1.Tables[_tableName];
}
catch (Exception ex)
{
//labo.modele.SYS_LOG_Modele.tracerException(ex, _reqSelect);
}
try
{
con.Close();
}
catch (Exception ex)
{
//labo.modele.SYS_LOG_Modele.tracerException(ex);
}
return daTable1;
}
}
2 - 然后我创建了一个数据集,名为“patient”的数据表与我的查询具有相同的模式:
DataTable dt = getResults("select id,nom,prenom from
app_patient","app_patient", 1);
3 - 我做的最后一件事是更改报表查看器的数据源:
//ReportParameter rp = new ReportParameter("ReportParameter1", "test test");
this.ReportViewer1.Reset();
this.ReportViewer1.Visible = true;
this.ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
//this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });
this.ReportViewer1.LocalReport.DataSources.Clear();
this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
//this.ReportViewer1.DataBind();
this.ReportViewer1.LocalReport.Refresh();
数据dt不是空的,我检查了它中的数据,我用SQL Server数据库试了一下,它运行得很好,但我确实需要使用MYSQL数据库。我不知道我的问题在哪里,报告查看器保持缓冲,但没有结果。