[Mono-list] SqlDBType.Money processed wrong with mono 2.6.4

Josef Semmler josef.semmler at gmail.com
Sun Jun 13 04:59:35 EDT 2010


Hi,

i'm either doing someing stupid - or there is a bug with handling
SqlDBType.Money in mono 2.6.4 ... please help me.

I have a sqlserver 2005 -  in a table with an attribute "Amount" of type
"Money" i try to store different values, which are in the c# code
represented as "decimal" - for any reason, the values are stored completly
wrong.
Here is a sample code, which tries to store different values:

using System;
using System.Data;
using System.Data.SqlClient;

namespace TestDecimalBugWithMono
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                AddItem((decimal)12);
                AddItem((decimal)12.3);
                AddItem((decimal)12.34);
                AddItem((decimal)12.345);
                AddItem((decimal)12.3456);
                AddItem((decimal)12.34567);
                AddItem((decimal)12.345678);
           }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

        static void AddItem(decimal amount)
        {
            string connectionString =
System.Configuration.ConfigurationManager.ConnectionStrings["testdata"].ConnectionString;

            using (SqlConnection connection = new
SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("INSERT INTO
TestData (Amount) VALUES (@Amount)", connection))
                {
                    command.CommandType = CommandType.Text;

                    SqlParameter parm = new SqlParameter("@Amount",
SqlDbType.Money);
                    parm.Value = amount;

                    command.Parameters.Add(parm);

                    int numRecordsAffected = command.ExecuteNonQuery();
                    Console.WriteLine("Nb record added: {0}",
numRecordsAffected);
                }
            }
        }
    }
}
When i run the code with mono 2.6.4 the following values end up in the
database:

0,0012
0,0123
0,1234
1,2345
12,3456
123,4567
1234,5678

This happens when using mono 2.6.4 - mono 2.4 and windows .net seem to store
the values correctly ...

What am i missing? Is this a bug?

thanks
Josef
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20100613/b75a2b54/attachment.html 


More information about the Mono-list mailing list