BUG? OleDb AccessMdb Localization

  • Thread starter Thread starter Jeroen Smits
  • Start date Start date
J

Jeroen Smits

I think I found a bug in .NET 1.1 using the OleDb classes

using:

..NET 1.1
Access MDB file (2000 format)
Localization set to Dutch (or probably any localization where the , is used
for decimal and . is used for thousands)

steps to reproduce problem:

Create a OleDbCommand with a sql statement like
INSERT INTO [TABLENAME] ( [DECIMALFIELDNAME] ) VALUES( ? )

Then use the Parameters.Add on the OleDbCommand to add a number for the ?
variable, that uses a decimal. For example 2.75m

After the insert executed the record appears as if no decimal sign was
there, in this case it would be 275 instead of 2.75

probable cause:

I think oledb (or access?) expects the value in local format, while
OldDbCommand.Parameters supplies the InvariantCulture version.
 
Hi,

Parameters should be immune to localization issues.
How is your parameter defined and your database field?
 
Miha said:
Hi,

Parameters should be immune to localization issues.
How is your parameter defined and your database field?

db-field:

DataType: Number
Field Size: Decimal
Precision: 18
Scale: 4
DecimalPlaces: 2

parameter:

decimal price = 2.75m;
cmd.Parameters.Add( "Price", price );
 
Hi Jeroen,

Try with this parameter declaration:
OdbcParameter p = new System.Data.Odbc.OdbcParameter("Price",
System.Data.Odbc.OdbcType.Decimal, 0, System.Data.ParameterDirection.Input,
false, ((System.Byte)(18)), ((System.Byte)(4)), "Price",
System.Data.DataRowVersion.Current, null);
cmd.Parameters.Add(p);

p.Value = 2.75m;
 
Miha said:
Hi Jeroen,

Try with this parameter declaration:
OdbcParameter p = new System.Data.Odbc.OdbcParameter("Price",
System.Data.Odbc.OdbcType.Decimal, 0,
System.Data.ParameterDirection.Input, false, ((System.Byte)(18)),
((System.Byte)(4)), "Price", System.Data.DataRowVersion.Current,
null);
cmd.Parameters.Add(p);

p.Value = 2.75m;

So I have to supply the definition of the field with the parameter. Ok I'll
try that as soon as I'm back home. Unfortunaly that means I can't use the
general method I wrote for inserting data anymore. I'll let you know if it
works.
 
Hi Jeroen,

Jeroen Smits said:
Miha Markic wrote:
So I have to supply the definition of the field with the parameter. Ok I'll
try that as soon as I'm back home. Unfortunaly that means I can't use the
general method I wrote for inserting data anymore. I'll let you know if it
works.

It is always a good thing to set such info at design time.
There is also OleDbCommandBuilder class that I don't recommend using.
 
Hi Jeroen,

Yes, you are correct.
It seems that it is reagional selection influenced.
If you state decimal symbol as "." it works - can you confirm it?
Parameters should not be affected by regional setting.
What a nasty bug if this is true.
 
Back
Top