如何从使用内部vba函数的ms访问查询中进行选择?

时间:2015-11-06 16:48:55

标签: c# vba ms-access oledb

我在MS访问数据库中有一个查询,我在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#中选择此查询时,它可以正常工作,我收到此错误:

  

未定义的功能'最大值'在表达中。

所以任何解决方案?

1 个答案:

答案 0 :(得分:0)

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