insert decimal in Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hallo

Im learning VB.net 2003 and now I like to insert a decimal in Access, but the number 10,25 is in Access 1025. The Access field is also decimal with 2 digets behind. I think it will be on the regional settings, because whenn I try with 10,25 then it works. But my variable is always format as 10,25. What must I do? Can anyone help me?
 
Yes, it sucks.
Even if you use parametrised stataments they will be region depending if I
recall properly.
What's your code anyway?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Christian Eichhorn said:
Hallo,

Im learning VB.net 2003 and now I like to insert a decimal in Access, but
the number 10,25 is in Access 1025. The Access field is also decimal with 2
digets behind. I think it will be on the regional settings, because whenn I
try with 10,25 then it works. But my variable is always format as 10,25.
What must I do? Can anyone help me?
 
You have either :

- to format your data in a language independant manner (ie 10.25 instead of
10,25)

- instead of passing directly values as "text" in a plain text SQL query you
could use parameters (don't know if supported by the Access provider) so
that you pass "true" typed data instead of text strings...

You'll have also a similar problem for dates...

Event if you still create plain text SQL queries it should be easier to use
a small helper layer rather than to format this yourself each time...

Patrice

--

Christian Eichhorn said:
Hallo,

Im learning VB.net 2003 and now I like to insert a decimal in Access, but
the number 10,25 is in Access 1025. The Access field is also decimal with 2
digets behind. I think it will be on the regional settings, because whenn I
try with 10,25 then it works. But my variable is always format as 10,25.
What must I do? Can anyone help me?
 
Patrice Scribe said:
You have either :

- to format your data in a language independant manner (ie 10.25 instead of
10,25)

I am afraid that this is regional depending, too. Didn't test it though.
- instead of passing directly values as "text" in a plain text SQL query you
could use parameters (don't know if supported by the Access provider) so
that you pass "true" typed data instead of text strings...

Oddly enough, parameters are regional depending.
 
Duh, ignore my previous post.

Column in access was set to Long Integer...
It should work if parametrised or by sending 1.1.
You might use InvariantCulture to format values, example:
string s = 1.1.ToString(CultureInfo.InvariantCulture);

Will always produce "1.1".
 
Duh, ignore my previous post - it doesn't suck :)

Column in access was set to Long Integer...
It should work if parametrised or by sending 1.1.
You might use InvariantCulture to format values, example:
string s = 1.1.ToString(CultureInfo.InvariantCulture);

Will always produce "1.1".
 
Hi Christian,

You should use ExecuteNonQuery() instead of Execute*Reader*.
Also, you should pass just zahl4 (no need to convert it to string).

What type if you table column holding the decimal number and how is the
parameter defined?
Check out the Access column's Scale property if you are using decimal
datatype (it should be non-zero if you want decimals).

Additonal note:
Instead of doing a loop you migh use KasseAdp.Update(KasseDS.Kasse) method.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Christian Eichhorn said:
Thanks, but it do not work.

thats my code:

Private Sub Zahlungbt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Zahlungbt.Click
 
Hi mih

in Access it is decimal with tow digit. I take the nonQuery method. If I make zahl4(System.Globalization.CultureInfo.InvariantCulture) it is a failure. The Parameters are generate by the assistent. it i
Me.KasseInsertCom.Parameters.Add(New System.Data.OleDb.OleDbParameter("Preisbrutto", System.Data.OleDb.OleDbType.Decimal, 0, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(2, Byte), "Preisbrutto", System.Data.DataRowVersion.Current, Nothing)

How works the KasseAdp.Update(KasseDS.Kasse)

Thanks for the awnser? Hope you excuse my bad english.
 
Hi,

Christian Eichhorn said:
Hi miha

in Access it is decimal with tow digit. I take the nonQuery method. If I
make zahl4(System.Globalization.CultureInfo.InvariantCulture) it is a
failure.

Yes, i can imagine that. Did you try with just zahl4?

The Parameters are generate by the assistent. it is
Me.KasseInsertCom.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Preisbrutto",
System.Data.OleDb.OleDbType.Decimal, 0,
System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(2,
Byte), "Preisbrutto", System.Data.DataRowVersion.Current, Nothing))

Seems correct.
How works the KasseAdp.Update(KasseDS.Kasse)?

Like your loop. :)
Thanks for the awnser? Hope you excuse my bad english.

No problem. We are not all native english speaker, are we :)
 
Hi,

I am curious.
Do you mind create me a sample and attach also mdb?
Send it to my e-mail address (adjust it before)
--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Christian Eichhorn said:
Thanks for the update command. It works very good! But always without the
decimalpoint!
 
Hello Miha
I send the database and the source to (e-mail address removed). I hope its right

Very thanks!!!!!!
 
I take a look and it seems that the problem is afteral, funny enough, in
combination of reagional settings and OleDbType.Decimal type.

When I set decimal separator as "," it won't work.

Try replacing OleDbType.Decimal with OleDbType.Double as a workaround.
 
Could it be because if parameters(10) uses a decimal data type ?

I believe the scenario could be :
- you take a decimal and convert it as text
- you now affect this text to a decimal parameter (and nedds to convert back
to decimal). The implicit conversion fails...

The key point is about conversions. If you use the same datatype at both end
you don't have to convert. The problem only arise when converting to or from
text. For example, text entered in textboxes are strings (even if the user
typed a "decimal" or a "date" value). You then have at some point to convert
the text entered by the user to a "true" numeric value or date before
storing this in the database.

Patrice

--

Christian Eichhorn said:
Thanks, but it do not work.

thats my code:

Private Sub Zahlungbt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Zahlungbt.Click
 
Hi Patrice,

No, it isn't the case.
The problem is that passing a *decimal* parameter to jet via oledb is
regional depending.
I think that jet internally uses some sort of conversion provided by
automation library (which may depend on regional setting - to make the case
worse, it might depend on reg. settings only on certain windows version)
 
Back
Top