Reputation: 301
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
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