Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

Problem with decimal fields.

Last post 12-17-2006 11:49 PM by James Westgate. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 12-14-2006 5:57 PM

    Problem with decimal fields.

    Hi,

    The following code raises a concurrency error:

    Person P = new Person();
    P.Id = 3;
    P.Select();
    P.Vat = 15.67M;
    P.Update() // Concurrency exception


    Database is MSSQL2005 and table has 3 columns: Id (Integer, auto), Name (String, Max(30)), Vat (Decimal, Precision 18, Scale 4)

    Please advise.
    Archer
    • 82.45.255.253
  • 12-14-2006 6:35 PM In reply to

    Re: Problem with decimal fields.

    Could you please post the code for the Person class?
    • 81.153.80.231
  • 12-14-2006 6:56 PM In reply to

    Re: Problem with decimal fields.

    Hi,

    Following is the Person class:

    class Person : Table
    {
    private int _Id;
    private string _Name;
    private decimal _Vat;

    [PrimaryKey(1,1)]
    public int Id
    {
    get
    {
    return _Id;
    }
    set
    {
    _Id = value;
    }
    }

    [Column, MaximumLength( 30 )]
    public string Name
    {
    get
    {
    return _Name;
    }
    set
    {
    _Name = value;
    }
    }

    [Column]
    public System.Decimal Vat
    {
    get
    {
    return _Vat;
    }
    set
    {
    _Vat = value;
    }
    }

    public Person()
    {
    }
    public Person( string Name, Decimal Vat, Context C )
    {
    this.Name = Name;
    this.Vat = Vat;
    this.Context = C;
    }
    }

    Regards,
    Archer
    • 82.45.255.253
  • 12-14-2006 6:58 PM In reply to

    Re: Problem with decimal fields.

    I have to add the following info:

    When the table is created, the VAT field is created as Decimal(18,0). I manually modify the field to be Decimal(18,2). Then I add the record manually with Vat field equal to 12.30

    If It was a 12.00 or any other whole number, the code above doesn't raise an exception but the updated value is rounded up.
    • 82.45.255.253
  • 12-15-2006 12:14 PM In reply to

    Re: Problem with decimal fields.

    Ops, I just realized why it didn't work.
    I've changed the field definitions manually but I forgot to change the stored procedures as well. Hence the values are updated by parameters with the old definitions.

    This immediately brings another question to my mind. Is it possible to specify column parameters like precision or scale on the class definition?
    • 82.45.255.253
  • 12-15-2006 7:07 PM In reply to

    Re: Problem with decimal fields.

    There should in fact be attributes for the special case of decimal,which is a fixed point and not a floating point data type.

    We will add this as a feature in the next release in the meantime you could change the procedures and table by hand, or use a floating point data type, such as float, double etc.
    • 81.153.80.231
  • 12-15-2006 8:00 PM In reply to

    Re: Problem with decimal fields.

    Ok great.

    Thanks.
    • 82.45.255.253
  • 12-17-2006 11:49 PM In reply to

    Re: Problem with decimal fields.

    This has now been addressed with the new Fixed attribute in build 1.0.2542. See the following post for more details:

    http://support.crainiate.net/Forums/forums/176/ShowPost.aspx#176
    • 81.153.80.231
Page 1 of 1 (8 items)