Crystal Report多次显示数据

时间:2017-08-06 08:15:21

标签: c# crystal-reports

我遇到一个问题,我在报告中获取数据4次,因为我填充数据适配器4次

这是我的代码:

MyCommand.CommandType = CommandType.Text;
myDA.SelectCommand = MyCommand;
myDA.Fill(myDS, "Stock");
myDA.Fill(myDS, "Stock_Product");
myDA.Fill(myDS, "Product");
myDA.Fill(myDS, "Supplier");

rd.Load(@"C:\Users\aliali\Documents\Visual Studio 2013\Projects\GenesysInventory System\GenesysInventory System\rptpurchase.rpt");
rd.SetDataSource(myDS);

frmReport obj = new frmReport();
obj.crystalReportViewer1.ReportSource = rd;
obj.ShowDialog();

1 个答案:

答案 0 :(得分:0)

工作流程是创建表格,填充表格,然后将它们添加到数据集,然后将数据集设置为报表数据源。

var dtStock = new DataTable("Stock");
MyCommand.CommandType = CommandType.Text;
myDA.SelectCommand = MyCommand;
myDA.Fill(dtStock, "Stock");
// another command for Stock_Product
var dtStockProduct =new DataTable("Stock_Product");
stockProductDA.SelectCommand = StockProductCommand;
stockProductDA.Fill(dtStockProduct, "Stock_Product");
// fill all the tables

// finally, add all the tables to your data set
myDS.Tables.Add(dtStock);
myDS.Tables.Add(dtStockProduct);
// continue as normal
rd.Load(@"C:\Users\aliali\Documents\Visual Studio 2013\Projects\GenesysInventory System\GenesysInventory System\rptpurchase.rpt");
rd.SetDataSource(myDS);

frmReport obj = new frmReport();
obj.crystalReportViewer1.ReportSource = rd;
obj.ShowDialog();