将双精度值保存到Access数据库从C# [英] Saving a double value to Access Database From C#

查看:277
本文介绍了将双精度值保存到Access数据库从C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我创建一个简单的数据库读取器,它只是从访问数据库的值到一个DataGridView。我连接他们与内置的帮助,以获得一个DataSource,如果你知道我的意思。一切都很好,但在值列,当我写下来说1172,44它将保存为117244在访问,所以,当我在应用程序上打开它的值是117244,因为它是保存的值。

So I'm creating a simple database reader which is only supposed to get values from an access database into a DataGridView. I connected them with the built in help to get a DataSource if you know what I mean. And everything is fine but on the "Value" column when I write down let's say 1172,44 it will save it as 117244 in access and so, when I open it on the application the value is 117244 since it's the saved value.

在访问和c#数据集中,fieldsize属性设置为double。我已经尝试为十进制,但它只是给我一个错误,我不能找出导致它的原因。似乎喜欢我,它不是读,作为一个逗号,但作为一个。这很可能使它是一个千分位数,只是删除它导致的数字没有逗号。任何人都知道我可以如何解决它?我可以得到你需要的任何代码,你只需要问。

Both in access and in the c# dataset the fieldsize property is set as double. I've tried as decimal but it just gives me an error which I can't find out what's causing it. Seems like to me that it is not reading "," as a comma but as a "." which most likely makes it a thousand-separator and just removes it resulting in the number without the comma. Anyone knows how i could fix it ? I can get any code you need here you just have to ask.

谢谢你,Bruno Charters。 (=

Thanks, Bruno Charters. (=

推荐答案

您可以尝试将存储在DataSet中的double值设置为与文化无关(不变)一个方法是使用 CultureInfo 格式提供程序来解析输入,下面的代码演示了1172的转换,44到 1172.44d

You could try setting the double value stored in the DataSet to be culture-independent (invariant) and control the representation of the group and decimal separators. One way to do this is parsing the input using the CultureInfo format provider. The code below illustrates the conversion of "1172,44" into 1172.44d

var culture = (CultureInfo) CultureInfo.InvariantCulture.Clone();
culture.NumberFormat.NumberDecimalSeparator = ",";
culture.NumberFormat.NumberGroupSeparator = "."; 
var a = double.Parse("1172,44", culture);

Console.WriteLine(a); //outputs 1172.44

这篇关于将双精度值保存到Access数据库从C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆