423,851 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,851 IT Pros & Developers. It's quick & easy.

saving decimal value

P: n/a
Hello

I'm developing a project by using access database and there is a
table(Table1) and it has a field(ml_mik) this is the decimal field.

I'm taking a value from windows form as a decimal variable(for example 12,3
or 12.3). After saving record, value(12,3 or 12.3) is saved as 123, not 12,3
or 12.3...

I'm using ADO.NET for processes in the database.

How can I accomplish this error? How can I save 12,3 value in the database?

Thanks for your helps.


Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Brenny,
you need to make sure that if you are parsing user data then you pass in
the Culture in which the data has been formatted so that it is parsed
correctly. For example if you enter an number like 123.45 then if you parse
that as an EN-US culture then the number will be interpretted as 123.45 but
if you parse it as a German format i.e. DE-DE then it will be 12345

For example:

//get the number 123.45
string decimalNumber = this.textBox1.Text;

//parse this as a EN-US culture -> it will be stored in dEnUs as 123.45
decimal dEnUs = Decimal.Parse(decimalNumber, new
System.Globalization.CultureInfo("en-us"));

//parse this as a DE-DE culture it will be parse as 12345
decimal dDeDe = Decimal.Parse(decimalNumber, new
System.Globalization.CultureInfo("de-de"));
After you have parsed the value correctly through the GUI it should be
stored correctly in your database.

Hope that helps
Mark R Dawson.
"Brenny" wrote:
Hello

I'm developing a project by using access database and there is a
table(Table1) and it has a field(ml_mik) this is the decimal field.

I'm taking a value from windows form as a decimal variable(for example 12,3
or 12.3). After saving record, value(12,3 or 12.3) is saved as 123, not 12,3
or 12.3...

I'm using ADO.NET for processes in the database.

How can I accomplish this error? How can I save 12,3 value in the database?

Thanks for your helps.



Nov 17 '05 #2

P: n/a
"Brenny" <br***********@gmail.com> ha scritto nel messaggio
news:uZ**************@TK2MSFTNGP10.phx.gbl...

I'm taking a value from windows form as a decimal variable
How?
The variable is well valued?
(for example 12,3
or 12.3). After saving record, value(12,3 or 12.3) is saved as 123, not 12,3 or 12.3...
How do you pass the variable?
Is this a string, so that it is "converted"?
How can I accomplish this error? How can I save 12,3 value in the

database?

Using the right data type for variables and the conversion function
according on the tipe of separator you want to use (localized or ".").

--
Reporting tool: http://www.neodatatype.net
Nov 17 '05 #3

P: n/a
Thanks Mark.

//get the number 123.45
string decimalNumber = this.textBox1.Text;

//parse this as a EN-US culture -> it will be stored in dEnUs as 123.45
decimal dEnUs = Decimal.Parse(decimalNumber, new
System.Globalization.CultureInfo("en-us"));

After this code,123.45 is saved as 12345

What are database field's attributes?

If database field's value is currency, I can hold 123.45 as 123.45 but If I
hold this number as decimal, I can't hold as a decimal.

Access database I'm using is Turkish.. Can error occur because of this?.
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.