【发布时间】: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# 中选择这个查询时,我得到了这个错误:
表达式中未定义函数“最大值”。
所以有什么解决办法吗?
【问题讨论】:
-
DMax 和 Max 在 MS Access 之外工作。你为什么要写一个函数?