使用ADODB从VBA中的Recordset获取小数 [英] Get decimals from Recordset in VBA with ADODB
本文介绍了使用ADODB从VBA中的Recordset获取小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从一个字段获取一个值,我不知道为什么是圆的
I'm trying to get a value from a field, I don't know why is rounded
rs.Open myQuery, cnn
i = 1
Do While rs.EOF = False
S1 = rs.Fields("S1")
Cells(i, 1) = S1
i = i + 1
rs.Next
Loop
例如,在数据库S1是8.567,但我总是得到8
For example, in the database S1 is 8.567 but I always get 8
有没有办法从该字段定义数据类型?
Is there a way to define the data type from that field?
谢谢!
推荐答案
我找到了解决方案,在你的查询中你必须定义你想拥有的数据类型。
I found the solution, in your query you have to define the type of data you want to have.
sqlQuery = "SELECT CAST(F1 AS DOUBLE) AS newValue FROM TABLE"
然后你会得到带有小数位数的newValue。
Then you will get newValue with decimals.
这篇关于使用ADODB从VBA中的Recordset获取小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文