在VBA中,我有一组ADO记录集,我希望在用户使用表单时对记录集中的值进行计算并将其存储在内存中 .
我的问题:在我做了一个计算,比方说,和整数之后,我得到了一个double / float . 当我尝试将其存储在记录集中时,它被转换/更改为整数 . 我希望保留计算后双精度/浮点数的精度 .
我的想法:更改我正在计算和存储的字段的数据类型 . I'm not seeing how to do it. 我该怎么做?我能这样做吗?
例如:
Option Explicit
Sub test()
Dim rs As ADODB.Recordset
Dim sql As String
sql = "select * from test;"
Set rs = frsGetPgRecordset(sql)
Do While rs.EOF = False
Debug.Print rs!x & "
Debug.Print Application.WorksheetFunction.Log(rs!x) & "
rs.Fields("x") = Application.WorksheetFunction.Log(rs!x)
Debug.Print rs!x & "
rs.MoveNext
Loop
End Sub
我明白了:
8
0.903089986991944
1
20
1.30102999566398
1
注意,这不是更改数据库,因为在frsGetPgRecordset中(不提供,因为它对问题不重要)我有:
rs.CursorType = adOpenKeyset
rs.CursorLocation = adUseClient
rs.LockType = adLockBatchOptimistic