Hello,
I just wanna do a simple operation. My sql query is below;
UPDATE IP_KONTROL SET up_down= '" + rdr["up_down"] + 1 + "' WHERE spe = '" + specif + "' ", conn
I just want to increase rdr's value 1, and Update it. I mean I want to increase rdr["up_down"]'s value. But it isnt adding +1. For example if rdr["up_dow"]'s value is 2, and then it is updating "21".. It should be "3", not "21". How can i do that?
Addition operating at a SQL query?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Subhendu DeRank #1,108 · 1.7K reputationPosted Dec 18, 2010, 6:24 PM EST
int i = 2;
int j = 1;
(i+j) would give you (2+1) = 3. The mathematical sum happens here.
string i = "2";
string j = "1";
(i+j) would give you ("2" + "1") = "21". The concatenation happens here.
So do in this way
UPDATE IP_KONTROL SET up_down= '" + Convert.ToString( (Convert.ToInt32(rdr["up_down"]) + 1)) + "' WHERE spe = '" + specif + "' ", conn
Convert the string to int and then do the sum. Again convert it to string.
Thanks.....
Suthish NairRank #92 · 22.8K reputationPosted Dec 19, 2010, 12:09 AM EST
For more, refer article.