【问题标题】:XtraReport : An object assigned to the DataSource property cannot be usedXtraReport:无法使用分配给 DataSource 属性的对象
【发布时间】:2012-12-03 04:33:01
【问题描述】:

我有一个使用存储在数据库中的报告的 C# 应用程序,对于使用 XPObject 作为数据源的特定报告(CptOperation 类,代码如下),我收到此错误消息尝试打印或预览时:

分配给 DataSource 属性的对象不能用作 报告的数据源,因为它没有实现任何支持的 接口。有关详细信息,请参阅 http://help.devexpress.com/#XtraReports/CustomDocument1179

这是我用来打印报告的代码。

public static void PrintReport(string reportCode, object dataSource, string printerName)
{
    using (var uow = new UnitOfWork { ConnectionString = Content.GlobalInfo.ServerConnectionString })
    {
        var report = uow.FindObject<Content.Report>(new BinaryOperator("Code", reportCode));
        if (report == null)
        {
            XtraMessageBox.Show(String.Format("The report {0} is not found", reportCode),
                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }

        var xtraReport = getXtraReportFromReport(report);
        xtraReport.DataSource = dataSource;

        if (!String.IsNullOrEmpty(printerName))
            xtraReport.Print(printerName);
        else
            xtraReport.Print();
    }
}

private static XtraReport getXtraReportFromReport(Content.Report report)
{
    XtraReport xtraReport;
    using (var writer = new StreamWriter(new MemoryStream()))
    {
        writer.Write(report.Content);
        writer.Flush();
        xtraReport = XtraReport.FromStream(writer.BaseStream, true);
    }
    return xtraReport;
}

这是我的对象持久性类“CptOperation”:

private CptTypeOperation cptTypeOperation;
public CptTypeOperation CptTypeOperation
{
    get { return cptTypeOperation; }
    set { SetPropertyValue<CptTypeOperation>("CptTypeOperation", ref cptTypeOperation, value); }
}

private int numero;
public int Numero
{
    get { return numero; }
    set { SetPropertyValue<int>("Numero", ref numero, value); }
}

private CptSession cptSession;
[Association("CptSession-CptOperation")]
public CptSession CptSession
{
    get { return cptSession; }
    set { SetPropertyValue<CptSession>("CptSession", ref cptSession, value); }
}

[Association("CptOperation-Piece")]
public XPCollection<Piece> Pieces
{
    get { return GetCollection<Piece>("Pieces"); }
}

[Association("CptOperation-Transact")]
public XPCollection<Transact> Transacts
{
    get { return GetCollection<Transact>("Transacts"); }
}

【问题讨论】:

  • 传递给PrintReportobject dataSource 的实际类型是什么?你能在调试器中检查这个吗?
  • 它应该是一个 CptOperation 对象。

标签: c# .net devexpress datasource xtrareport


【解决方案1】:

问题出在我发送XPObject类型的对象作为报告数据源,但实际上xtraReport数据源必须是IListIList&lt;T&gt;对象,例如,它可以是类型: XPCollection&lt;CptOperation&gt;List&lt;CptOperation&gt;...

【讨论】:

    猜你喜欢
    • 2021-06-30
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    • 2021-05-12
    • 2019-04-27
    • 2017-12-18
    • 2023-03-13
    相关资源
    最近更新 更多