How to use Two Tables with Crystal Reports

时间:2016-07-11 22:36:57

标签: c# crystal-reports

I have a report in Crystal Reports. I would like to use two tables. I set up the data table like below. In the report designer, I select both the customer and the trans tables. I designed my report but nothing shows up (empty report). I take away the customer table in the report designer and, voila, data appears. I really need the customer data, too, though. I know I can accomplish this using a view however I am trying to avoid the overhead of that because I'm going to have dozens upon dozens of reports and I don't want to have a view for each.

    public void ConfigureCrystalReports()
    {
        Shared_Items.UtilitiesClass ru = new UtilitiesClass();
        string cs = ru.getConnectionString();

        string sql = "select a.*, b.cust_name from trans a left outer join customer b on a.customer = b.customer  where a.customer  like '"+customerFinder+"'";

        SqlConnection cx = new SqlConnection(cs);
        cx.Open();

        SqlDataAdapter ta = new SqlDataAdapter(sql, cx);

        DataSet ds = new DataSet();

        ta.Fill(ds);

        // declare the report
        ControlsTransactionSummaryBycustomer report = new ControlsTransactionSummaryBycustomer();

        report.SetDataSource(ds.Tables[0]);

        // Binding the crystalReportViewer with our report object. 
        crystalReportViewer1.ReportSource = report;
        crystalReportViewer1.Refresh();
        crystalReportViewer1.Show();
    }

0 个答案:

没有答案