小编典典

如何将水晶报表绑定到手动创建的数据集

c#

我不会从代码创建DataSet并将其设置为Crystal Report的数据源。
如果不想的话,我不想在VS中创建DataSet xsd文件。只是纯代码。

DataSet ds = new DataSet();
DataTable tbl = new DataTable();
DataColumn cln = new DataColumn();
// I fill row, columns, table and add it to ds object
...

然后,当我需要报告时,我使用:

myReport.SetDataSource(ds);

这里的问题是我不知道如何将其绑定到报告?如何添加字段?
我有一个文本和二进制数据(图像)。


阅读 588

收藏
2020-05-19

共1个答案

小编典典

唯一的出路。正如罗萨多建议的那样。一点解释1.创建一个RPT文件。2.使用所需的列创建一个XSD。3.将列拖放到rpt上。根据需要对其进行格式化。4.现在创建连接,使用适配器填充该数据集。5.填充数据集将自动填充报告列。

下面是一个矿山项目的示例代码。

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();
2020-05-19