来自DataSet中两个不同DataTable的数据不会显示在Crystal Report中

时间:2014-12-15 06:52:31

标签: c# crystal-reports

我需要从两个表创建一个报告库: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;
    }

0 个答案:

没有答案