saving decimal value

  • Thread starter Thread starter Brenny
  • Start date Start date
B

Brenny

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.
 
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" <[email protected]> ha scritto nel messaggio

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 ".").
 
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?.
 
Back
Top