【问题标题】:C# windows Crystal Reports, How to display a data table in crystal reports programmaticallyC# windows Crystal Reports,如何以编程方式在水晶报表中显示数据表
【发布时间】:2017-02-02 15:31:38
【问题描述】:

这是我的代码,运行代码时出现错误。

private void Form2_Load(object sender, EventArgs e)
{
    string sql = "SELECT * FROM Worker ";
    SqlConnection connection = new SqlConnection(connectonString);
    SqlDataAdapter da = new SqlDataAdapter(sql, connection);
    DataTable dt = new DataTable();

    da.Fill(dt);
    CrystalReport1 cr = new CrystalReport1();
    cr.SetDataSource(dt);

    crystalReportViewer1.ReportSource = cr;
    crystalReportViewer1.Refresh();
}

【问题讨论】:

标签: c# database windows


【解决方案1】:

重复的问题: How to Bind Crystal Report to manually created Dataset

你需要做这样的事情:

            Invoice invoice = new Invoice(); // instance of my rpt file
            var ds = new DsBilling();  // DsBilling is mine XSD
            var table2 = ds.Vendor;
            var adapter2 = new VendorTableAdapter();
            adapter2.Fill(table2);


            var table = ds.Bill;
            var adapter = new BillTableAdapter();
            string name = cboCustReport.Text;
            int month = int.Parse(cboRptFromMonth.SelectedItem.ToString());
            int year = int.Parse(cboReportFromYear.SelectedItem.ToString());
            adapter.Fill(table, name,month,year);

            ds.AcceptChanges();

            invoice.SetDataSource(ds);
            crystalReportViewer1.ReportSource = invoice;
            crystalReportViewer1.RefreshReport();

【讨论】:

    猜你喜欢
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    相关资源
    最近更新 更多