locked
SqlDatasource update values how to ? RRS feed

  • Question

  • User-909867351 posted

    Hi

    I'm working with Mysql database and I need to update one field. Here is my code

     SqlDataSource1.UpdateParameters.Clear();
            SqlDataSource1.UpdateCommand = "update contas set valor=valor+? where conta='1.1' and codigo=?";
            SqlDataSource1.UpdateParameters.Add("@a", txtValor.Text);
            SqlDataSource1.UpdateParameters.Add("@b", Session["edificio"].ToString());
            SqlDataSource1.Update();

    The problem is that I can only pass string as parameter and not decimal values therefore my field is never updated. How can I work with decimal parameters?

    Thank you

    Friday, December 6, 2019 5:35 PM

Answers

  • User-909867351 posted

    Found it

    SqlDataSource1.UpdateParameters.Clear();
            SqlDataSource1.UpdateCommand = "update contas set valor=valor-cast('" + txtValor.Text + "' AS DECIMAL(12,2)) where conta='1.1' and codigo=?";               
            SqlDataSource1.UpdateParameters.Add("@b", Session["edificio"].ToString());
            SqlDataSource1.Update();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 7, 2019 12:18 PM