Crystal Reports返回" DataSet不支持System.Nullable"存储过程

时间:2017-03-02 16:57:24

标签: c# asp.net entity-framework stored-procedures crystal-reports

我在ASP .NET Web项目上显示Crystal Report时出现问题。这是我的#34;查看报告"按钮代码:

private void ViewReport(int bankID, DateTime dateFrom, DateTime dateTo)
{
   ReportDocument report = new ReportDocument();
   report.Load(Server.MapPath("~\\Reports\\rptBankTransactionsList.rpt"));
   report.SetDataSource(bankEntities.spBankTransactionsList(bankID, dateFrom, dateTo).ToList());
   report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "TransactionsList");
}

我正在使用Entity Framework,而spBankTransactionsList存储过程正在返回正确的值。我甚至使用完全相同的存储过程在GridView中显示结果没有问题。该报告使用的DataSet具有与存储过程完全相同的结果值。

这是存储过程:

ALTER PROCEDURE [dbo].[spBankTransactionsList] 
@bankID AS INT,
@dateFrom AS DATETIME2,
@dateTo AS DATETIME2
AS

BEGIN

    SELECT B.BankID, B.BankName, BT.Date, BT.Description, BT.Amount
    FROM Bank B
    INNER JOIN BankTransaction BT ON B.BankID = BT.BankID
    WHERE B.BankID = @bankID
    AND BT.Date BETWEEN @dateFrom AND @dateTo
END

我有几个报告具有相同的情况,这是唯一一个返回我的" DataSet不支持System.Nullable"加载报告时出错。存储过程结果没有显示任何空值,正如我所说,GridView中的结果是正常的。

如果存储过程结果的行为零,则报告加载正常,显然没有记录但加载!我错过了什么?

先谢谢。

1 个答案:

答案 0 :(得分:0)

问题出现在其他报告和SP中,所以最后我提出了解决方案。

虽然在我的SP中我确保结果上没有空值,不知何故,当实体框架将SP放入模型时,它“假设”某些列可能是可空的。

解决方案是进入Model Explorer,选择实体模型,然后在复杂类型中搜索SP的结果类型(在我的例子中是“spBankTransactionsList_Results”,展开它并检查每个属性是否具有可为空的值假的。

希望这可以解决同样问题的其他人。