简体   繁体   English

将文本字符串转换为十进制或货币类型,以便在C#中进行ms-access查询?

[英]Convert text string to Decimal or currency type for ms-access query in C#?

I want to run a query that converts the text from the field into a number or currency field. 我想运行一个查询,将字段中的文本转换为数字或货币字段。

I have a query like : 我有一个查询,如:

SELECT * FROM qryProjectData ORDER BY prj.ProjectDisplayNo

I have data like. 我有类似的数据。

362
362.01
362.2
362.3
362.4
362.5
362.6
362.7
362.8
362.9
362.10
362.11

I did sorting on it But result is like below. 我对它进行了排序,但结果如下所示。

362
362.01
362.10
362.11
362.2
362.3
362.4
362.5
362.6
362.7
362.8
362.9

Problem is it is text field, that why not sorting properly. 问题是文本字段,为什么不正确排序。 Need to convert it into Decimal or currency type. 需要将其转换为十进制或货币类型。

Help me, if anyone have solution. 如果有人有解决方案,请帮助我。

We can do it by....... 我们可以做到的.......

SELECT CCur(val(your_field_name))
FROM qryProjectData
ORDER BY prj.ProjectDisplayNo;

You can use CDec , CSng , and CDbl to covert text datatype to numeric, currency, sign and double.. 您可以使用CDecCSngCDbl将文本数据类型转换为数字,货币,符号和双CDec

You can use the CCur function like this: 您可以像这样使用CCur函数:

SELECT CCur(your_field_name) FROM qryProjectData ORDER BY prj.ProjectDisplayNo;

Keep in mind that there are also CDec , CSng , and CDbl functions as well that work the same way. 请记住,还有CDecCSngCDbl函数也以相同的方式工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM