gpt4 book ai didi

sql-server-2005 - 试图让 Reporting Services 理解我的代码

转载 作者:行者123 更新时间:2023-12-04 05:13:08 26 4
gpt4 key购买 nike

我正在尝试将一些我在报告中经常需要的表达式封装到报告函数中,以便我可以编写一次代码并在报告中的任何地方使用它。但我真的是一个 Pascal/C# 程序员,并且在与 VB(A) 语法斗争......
但即使是这个小小的日期格式化功能也不知何故不起作用......

Public Function DateFmt (ByVal dt As DateTime) As String
Return IIF(IsNothing(dt), "", FormatDateTime(dt, 2))
End Function
基本上,如果 DateTime字段是 NULL在数据库中,我想显示一个空字符串(空单元格),否则使用“短日期”格式选项。
在单元格上,我试图将其添加为单元格表达式,但是当我开始键入这样的表达式时:
=Code.
智能感知开始了,但我的功能没有显示在那个列表中......嗯......我错过了什么?

Update: I noticed that while intellisense doesn't work, I can still put the expression =Code.DateFmt(.....) into the cell - but alas, it doesn't work.

While adding the expression directly nicely suppresses NULL dates in display, using this shared function causes NULL dates to show up as 01.01.0001 again in my report. WHY?


另外:我需要一个函数,它根据选项列表返回一个值 - SWITCH声明基本上。这里的代码正确吗?
Public Function GetGrp(ByVal grp As String)
Select Case grp
Case "Region"
Return fields!RegionId.Value
Case "Somedate"
Return YEAR(Fields!Somedate.Value)
End Select
End Function
该函数实际上会导致编译失败,并显示以下错误消息:

Error in line 7 of user-defined code: [BC30469] Reference to a non-public member requires an object instance


?!?!?!?!? SSRS 到底想告诉我什么?
更新 #2:
好的,想通了这个 - Fields集合在自定义代码中不可用(不清楚为什么不可用 - 无论如何......)。
所以我需要将此功能更改为:
Public Function GetGrp(ByVal grp As String, ByVal fields As Fields)
现在这部分起作用了

最佳答案

IsNothing vbscript 表达式在自定义 VB 代码中似乎不能很好地工作。如果您将自定义代码更改为此,它可能会起作用:

Public Function DateFmt (ByVal dt As DateTime) As String
Return IIF(dt = Nothing, "", FormatDateTime(dt, 2))
End Function

蒸馏自 this related question 的溶液.

关于sql-server-2005 - 试图让 Reporting Services 理解我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14642095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com