我现在正在看一下XtraReports报告工具,还有一些我还没有得到的东西。
如何设置某个字段的数据源(在报告中显示为我猜的标签),而不必在设计时构建连接,适配器和数据集,而是以编程方式进行。
例如,我可以有一个名为“User”的表,其中包含3个字段:UserId,Username和Password。 在报表设计器中,我放置3个标签(这是我的问题)设置数据源以显示3个数据库字段。 然后,在后面的代码中,我创建一个连接,执行命令,填充数据集,创建一个报表实例,将数据表传递给它并显示报表预览。
这可能吗?如果不够清楚,请告诉我。
谢谢!
答案 0 :(得分:12)
您可以将Report的DataSourceSchema属性设置为表示DataSource的XML架构。这样您就可以使用报表设计器在设计时设置数据绑定,而无需每次都建立与数据库的连接。
我是这样做的: 一旦我的报告查询大部分完成,我通过调用
运行一次代码myDataSet.WriteXml("C:\myDataSourceSchema.xml", System.Data.XmlWriteMode.WriteSchema)
然后在报表设计器中,我将Report的DataSourceSchema属性设置为新创建的文件。这将填充报表设计器的“字段列表”选项卡,以便您可以在设计时进行绑定。这样,您只需拥有一次有效的数据源(或任何时候更改列)。您绝对可以使用Przemaas的方法并在代码中执行所有数据绑定,但我更愿意让设计人员处理大部分工作。
答案 1 :(得分:5)
是的,有可能。您可以在代码中定义必要的数据绑定:
this.xrLabel1.DataBindings.Add(new DevExpress.XtraReports.UI.XRBinding("Text", data, "Name", "aaa"));
XtraReport中的数据绑定基本上与标准窗体数据绑定相同。
让我知道您需要更多指南
答案 2 :(得分:5)
构建没有数据集的报表,您将使用IList对象...所以请遵循这个很好的教程
如何:将网络报告绑定到数组列表 https://documentation.devexpress.com/#XtraReports/CustomDocument3851
答案 3 :(得分:2)
这是一个替代..
rtpObject.DataSourceSchema = dataSet.GetXmlSchema();
答案 4 :(得分:1)
在将此修饰符属性设置为public
之前InvoicePrinting_Rpt InvoicePrintingRpt = new InvoicePrinting_Rpt();//report object
InvoicePrintingRpt.BillDetails.Report.DataSource = ds_Invoice;
InvoicePrintingRpt.Report.DataMember = ds_Invoice.Tables[0].TableName;
//bellow third parameter as your column name.
InvoicePrintingRpt.lbl_BillHead.DataBindings.Add("Text", null, "BILL_DESCRIPTION");
InvoicePrintingRpt.lbl_Det_Date.DataBindings.Add("Text", null, "TRANSACTION_DATE");
InvoicePrintingRpt.lbl_ISINCode.DataBindings.Add("Text", null, "ISIN_CODE");
ReportViewer1.Report = InvoicePrintingRpt;//assign report obj
ReportViewer1.Report.Name = "DevExpress_Reports.InvoicePrinting_Rpt";
ReportViewer1.DataBind(); //binding
答案 5 :(得分:1)
XRBinding binding = new XRBinding("Text", ageingBindingSource, "ageing_contactsLookup.name");
this.xrLabel19.DataBindings.Add(binding);
//或//
XRBinding binding = new XRBinding("Text", dbaDataSet, "transactions.fk_transitems_transactionid.name2");
this.xrTableCell1.DataBindings.Add(binding);