【问题标题】:How can I select from ms access query that uses an internal vba function?如何从使用内部 vba 函数的 ms 访问查询中进行选择?
【发布时间】:2015-11-06 16:48:54
【问题描述】:

我在一个 MS Access 数据库中有一个查询,我在 C# 应用程序中从中选择。 在这个查询中,我需要创建一个显示两个值的最大值的列,但是由于 ms 访问没有这个,所以我不得不在 vba 中编写自己的函数,如下所示:

Public Function Maximum(ParamArray FieldArray() As Variant)
' Declare the two local variables.
Dim I As Integer
Dim currentVal As Variant

' Set the variable currentVal equal to the array of values.
currentVal = FieldArray(0)

' Cycle through each value from the row to find the largest.

For I = 0 To UBound(FieldArray)
   If FieldArray(I) > currentVal Then
      currentVal = FieldArray(I)
   End If
Next I

' Return the maximum value found.
Maximum = currentVal
End Function

当我在 ms 访问中运行查询时,它工作得很好,但是当我尝试从 C# 中选择这个查询时,我得到了这个错误:

表达式中未定义函数“最大值”。

所以有什么解决办法吗?

【问题讨论】:

标签: c# vba ms-access oledb


【解决方案1】:

如果不使用某种类型的自动化,您将无法访问该功能。 最简单的方法是将记录放入数据表中,向其中添加另一列并循环遍历行,使用 C# 函数填充具有最大值的列。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多