Ange1
Ange1

Reputation: 301

Update query returns wrong values

I have this function:

 virtual public bool EditVideoNumber(String oldnumber, String channelnumber)
    {
        using (var con = GetConnection())
        {
            con.Open();
            var cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText += "update Videos set number=REPLACE(number,@oldnumber,@channelnumber)";
            cmd.Parameters.Add(new SqlParameter("@channelnumber", channelnumber));
            cmd.Parameters.Add(new SqlParameter("@oldnumber", oldnumber));
            try
            {
                cmd.ExecuteScalar();
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }

The problem is that, in the moment that i update the value oldnumber, from 102 to 1020 (just an example), it returns as a value 10200. i have tried to change the query several times, but nothing seems to make it work

Upvotes: 1

Views: 95

Answers (1)

Hamdi Baligh
Hamdi Baligh

Reputation: 892

You can try this. This will replace your current number value, with an other value with 0 appended at the end:

cmd.CommandText += "update Videos set number=REPLACE(number,number,CONTACT(number,'0'))";

Upvotes: 1

Related Questions