Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I use this method to increase value of logins column by one:

MySqlConnection connect = new MySqlConnection(connectionStringMySql);
MySqlCommand cmd = new MySqlCommand();

cmd.Connection = connect;
cmd.Connection.Open();

string commandLine = null;
commandLine = "UPDATE Users SET logins = (@cur_value := logins) + 1 WHERE id = @id;";

cmd.CommandText = commandLine;


cmd.Parameters.AddWithValue("@id", userId);

cmd.ExecuteNonQuery();
cmd.Connection.Close();

And i get this Exception:

Fatal error encountered during command execution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
151 views
Welcome To Ask or Share your Answers For Others

1 Answer

Just try this code

string commmandLine = "UPDATE Users SET logins = logins + 1 WHERE id = @id";
cmd.Set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...