在 VBA 中,我可能有这样的东西:
Dim recordSet As DAO.recordSet
result = recordSet("Column Name")
我试图在 C# 中做同样的事情,但是
result = recordSet("Column Name");
不会工作,因为 C# 使用方括号进行集合。但这似乎也不起作用:
result = recordSet["Column Name"];
关于上述 VBA 代码的 C# 等价物有什么想法吗?
编辑:这是我试图将其转换为上下文的完整 VBA 代码
Public Function GetColumnValues( _
database As database, _
column As String, _
table As String _
) As String()
Dim sqlQuery As String
Dim recordSet As DAO.recordSet
Dim recordCount As Integer
Dim results() As String
sqlQuery = "SELECT [" + table + "].[" + column + "]" & _
"FROM [" + table + "];"
Set recordSet = database.OpenRecordset(sqlQuery)
recordSet.MoveLast
recordSet.MoveFirst
recordCount = recordSet.recordCount
ReDim results(recordCount) As String
For i = 1 To recordCount
results(i) = recordSet(column)
recordSet.MoveNext
Next i
recordSet.Close
GetColumnValues = results
End Function