开发者

Problem passing decimal value to database (Access)

I want to pass decimal value to database table. When I send value 1,5 to database then save value as 15.

Code:

txtKm.Text="1,5";
zelezniceDataSet.VozniRediRow row;
row.Km = deci开发者_运维技巧mal.Parse(txtKm.Text);

zelezniceDataSet.VozniRedi.AddVozniRediRow(row);
vozniRediTableAdapter.Update(zelezniceDataSet.VozniRedi);

When debug decimal parsing the value is correct (1.5)


You probably want to look at an overloaded form of decimal.Parse that accepts a culture-specific format option. My guess is decimal.Parse sees your comma as a thousands-separator and just removes it.


seems to me that decimal.Parse is ignoring the comma ... if you pass "1.5" is the correct value saved? If so then you need to use the overload that takes the culture to use when parsing Decimal.Parse(String, NumberStyles) and pass it the correct number style for the language you are using.

EDIT ... more info ..

decimal.Parse(test, CultureInfo.GetCultureInfo("EN-us").NumberFormat );

will output 15 for test = "1,5" because in English the "," char is the thousands separator

decimal.Parse(test, CultureInfo.GetCultureInfo("NL-nl").NumberFormat );

will output 1.5 for test = "1,5" because in Dutch the "," char is the decimal separator

Hope this helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜