我需要从两个表创建一个报告库:patientinformation_tbl和daterecords_tbl 我已成功从两个表中检索了我需要的数据,并将其添加到dataSet中。 当我构建程序时,创建的报告是空白的。
以下是我创建报告的代码:
DataSet1 ds = new DataSet1();
DataTable info = _printResult.sample();
DataTable date = _printResult.sample2();
ds.Tables.Add(info);
ds.Tables.Add(date);
CrystalReport1 report = new CrystalReport1();
report.SetDataSource(ds);
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.Refresh();
表示我的sample()代码:
public DataTable sample()
{
string query = "SELECT * FROM patientinformation_tbl";
DataTable _data = new DataTable("patientinformation_tbl");
try
{
_connection.Open();
MySqlCommand command = new MySqlCommand(query, _connection);
command.CommandType = CommandType.Text;
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
adapter.Fill(_data);
}
catch (MySqlException ex) { }
_connection.Close();
return _data;
}
for sample2()代码:
public DataTable sample2()
{
string query = "SELECT * FROM daterecords_tbl LIMIT 1";
DataTable _data = new DataTable("daterecords_tbl");
try
{
_connection.Open();
MySqlCommand command = new MySqlCommand(query, _connection);
command.CommandType = CommandType.Text;
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
adapter.Fill(_data);
}
catch (MySqlException ex) { }
_connection.Close();
return _data;
}