当前位置: 首页 > 面试题库 >

表达式中未定义的函数“ Nz”

朱保赫
2023-03-14
问题内容

我已经用Google搜索了此错误,还没有得出为什么我会收到此错误的结论。我正在尝试用一些数据填充DataGridView。这是我的代码。

Private Sub LoadGrid()
    Dim cmd As New OleDbCommand
    Dim dt As DataTable
    With cmd
        .CommandText = "project_master_query"
        .CommandType = CommandType.StoredProcedure
        .Connection = New OleDbConnection(My.Settings.cnnString)
    End With
    dt = GetData(cmd)
    dgvData.DataSource = dt
End Sub

Private Function GetData(ByVal cmd As OleDbCommand) As DataTable
    Dim dt As New DataTable
    Using cmd.Connection
        cmd.Connection.Open()
        dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection))
    End Using
    Return dt
End Function

查询存储在Access中的“ project_master_query”。

    SELECT project_master.*, location_master.LocationName,
    project_currentmilestonedef.MilestoneDefID, 
    project_currentmilestonedef.MilestoneName, project_regions.RegionName,
    owner_fullname.FullName AS OwnerFullName, designer_fullname.FullName AS DesignerFullName,
    project_issuecount.HasOpenIssues, project_updated_closedate.UpdatedCloseDate, 
    project_bonusdays.BonusDays, project_bonusdays.IsGreen, project_bonusdays.IsYellow, 
    project_bonusdays.IsRed, checklist_days_perproject_defined_1.Week1, 
    checklist_days_perproject_defined_1.Week2, checklist_days_perproject_defined_1.Week3, 
    checklist_days_perproject_defined_1.Week4, project_issueduration.ProjectIssueDurationDays, 
    project_active_status.ProjectIsOpen, project_requirement_status.RequirementStatusName, 
    priority_def.PriorityShortName
    FROM project_requirement_status 
    RIGHT JOIN (project_regions 
    RIGHT JOIN (priority_def RIGHT JOIN (location_master 
    RIGHT JOIN ((((checklist_days_perproject_defined AS checklist_days_perproject_defined_1 
    RIGHT JOIN ((((((((contacts_fullname AS designer_fullname 
    RIGHT JOIN (contacts_fullname AS owner_fullname 
    RIGHT JOIN project_master ON owner_fullname.ContactID = project_master.ContactOwner) 
    ON designer_fullname.ContactID = project_master.ContactDesigner) 
    LEFT JOIN project_issuecount 
    ON project_master.ProjectID = project_issuecount.ProjectID) 
    LEFT JOIN project_currentmilestonedef 
    ON project_master.ProjectID = project_currentmilestonedef.ProjectID) 
    LEFT JOIN project_within_benchmark_week1 
    ON project_master.ProjectID = project_within_benchmark_week1.ProjectID) 
    LEFT JOIN project_within_benchmark_week2 
    ON project_master.ProjectID = project_within_benchmark_week2.ProjectID) 
    LEFT JOIN project_within_benchmark_week3 
    ON project_master.ProjectID = project_within_benchmark_week3.ProjectID) 
    LEFT JOIN project_updated_closedate 
    ON project_master.ProjectID = project_updated_closedate.ProjectID) 
    LEFT JOIN checklist_days_perproject_defined 
    ON project_master.ProjectID = checklist_days_perproject_defined.ProjectID) 
    ON checklist_days_perproject_defined_1.ProjectID = project_master.ProjectID) 
    LEFT JOIN project_issueduration 
    ON project_master.ProjectID = project_issueduration.ProjectID) 
    LEFT JOIN project_active_status 
    ON project_master.ProjectID = project_active_status.ProjectID)    
    LEFT JOIN project_bonusdays ON project_master.ProjectID = project_bonusdays.ProjectID) 
    ON location_master.LocationID = project_master.Location) 
    ON priority_def.PriorityDefID = project_master.ProjectPriority) 
    ON project_regions.RegionID = project_master.Region) 
    ON project_requirement_status.RequirementStatusID = project_master.RequirementStatus;

如您所见,查询中根本没有Nz,所以我根本不明白为什么会这样。一旦调用dt.Load,就会发生该错误。


问题答案:

Nz函数最有可能在许多联接之一中引用的视图/查询中。您必须仔细阅读所有这些内容。

由于Nz()是Access应用程序(而不是Access驱动程序)的功能,因此,当您尝试从Access应用程序外部使用它时,它将失败。您可以替换NzIIf(IsNull())结构。

请参阅IIf和的文档IsNull

放在一起时:

Nz(expr, [valueifnull])

变成

IIf(IsNull(expr), valueifnull, valueifnotnull)

例子

默认: Nz(tbl.A) => IIf(IsNull(tbl.A), '', tbl.A)

有后备html" target="_blank">功能: Nz(tbl.A, tbl.B) => IIf(IsNull(tbl.A), tbl.B, tbl.A)



 类似资料:
  • 问题内容: 我正在使用Access数据库,并尝试加载DataTable对象,但收到错误消息。我的查询在标准访问模块内调用一个名为“ CountWeekDays”的公共函数,当通过Access本身运行时,会返回正确的结果。通过.NET应用程序调用时,为什么这不起作用? 问题答案: 只有在Access本身中运行查询时,才可以在Access查询中使用用户定义的VBA函数。如果要从.NET应用程序中运行查

  • 当定义一个异步函数时,我通常会选择 我想切换到lambda表达式。我试过了 和 我认为第二个示例不起作用,因为这段代码将尝试将函数结果存储到中 是否可以用lambda表达式定义函数,或者它们只在其他函数中使用?

  • 我搜索了谷歌和Stackoverflow,但我找不到我的问题的答案。 我目前正在使用Jaspersoft Studio 5.6.2 final,我试图在我的表达式编辑器中显示一个自定义函数,但无论我如何尝试,我都无法显示类别和函数。 我开始关注 https://community.jaspersoft.com/wiki/jaspersoft-studio-expression-editor-how

  • 在 JavaScript 中,函数不是“神奇的语言结构”,而是一种特殊的值。 我们在前面章节使用的语法称为 函数声明: function sayHi() { alert( "Hello" ); } 另一种创建函数的语法称为 函数表达式。 通常会写成这样: let sayHi = function() { alert( "Hello" ); }; 在这里,函数被创建并像其他赋值一样,被明确地

  • 我一直在学习udemy的课程,但无论我做什么,都会出现一个错误: 以下是组件代码: 下面是我要导入的图表组件: 但显然是反应。组件未定义,所以它会抛出一个错误。

  • 跟踪这个问题的问题无法解决我的问题。 reactjs给出错误未捕获类型错误:超级表达式必须为空或函数,而不是未定义 我的反应版本是"^15.3.1"。 我添加了下面的代码片段