#24 Update fails with float

open
nobody
None
5
2004-10-22
2004-10-22
No

Hello,
ever tried to update a table with float-columns with the
autogenerated update-command??

It will ALWAYS fail because the comparation of the float
values will never match.

The where-clause of the update command should use
the primary key.

Stephan

Discussion

  • Locke
    Locke
    2006-09-29

    Logged In: YES
    user_id=1609564

    With double it's the same:

    foo = 2350.44;

    MySQLUpdateCommand MySQLsaveRohstoffe = new
    MySQLUpdateCommand(con,
    new object[,] {{"iFoo",(int) foo},{"fFoo",(float)
    foo},{"dFoo",(double) foo}},
    "bar",
    new object[,] {{"id","=",id}},
    null
    );

    creates the following SQL-Command

    update fornax.rohstoffe set foo=2350 , , WHERE id = 1

     
  • Locke
    Locke
    2006-09-29

    Logged In: YES
    user_id=1609564

    Sorry, I mean the following. I've copied something wrong:

    update bar set iFoo=2350 , , WHERE id = 1

     
  • rmccullough
    rmccullough
    2008-01-18

    Logged In: YES
    user_id=1152063
    Originator: NO

    You can fix this by editing MySQLUpdateCommand.cs. Find the line that has:
    if (Value.GetType() == typeof(int))
    Change it to
    if (Value.GetType() == typeof(int) || Value.GetType() == typeof(double) || Value.GetType() == typeof(float))

    I would also recommend adding this to the end of the big if/else block:
    else
    {
    throw new Exception("The value for " + Field + " is an unhandled type (" + Value.GetType() + ").");
    }