使用 SetParameterValue 将空日期传递给 crystal 报告参数

Pass a null date to a crystal report parameter using SetParameterValue

我有一个 crystal 报告,其中我通过 rdoc.SetParameterValue 传递开始和结束日期这工作正常,除了,我不希望它显示日期如果我不为日期变量传递任何内容,我只希望它为空白

为了尝试这样做,我写了

    if (DateStart != defaultDate)
    {
        rdoc.SetParameterValue("DStart", DateStart);
    }else
    {
        rdoc.SetParameterValue("DStart", "");
    }

这给了我错误 The types of the parameter field and parameter field current values are not compatible 当然,这是有道理的,因为我正在尝试将日期设置为字符串变量。 但是,我想不出解决方案,在参数菜单中也没有看到任何解决方案。

如果能给我一些帮助来解决这个问题,我将不胜感激。

此致

您可以将参数类型更改为字符串并将日期作为字符串传递:

DateStart.ToString()

我不喜欢这个解决方案,但它确实有效。通常我只需要日期。