c# Mysql Update Statement not reflect in other client

96 views Asked by At

I create simple mysql update statement in c#

string old_string = string.Empty;
string new_string = string.Empty;

using (MySqlConnection cn = new MySqlConnection("Server=hostaddress;Port=3306;Database=dbName;Uid=username;Pwd=password;"))
{
    cn.Open();
    try
    {
        string sql_old = @"select * from TBL_VERSION WHERE Id = 1 LIMIT 1";

        using (MySqlCommand cmd = new MySqlCommand(sql_old, cn))
        {
            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                reader.Read();
                old_string = reader["pos"].ToString();
            }
        }

        string sql = @"UPDATE TBL_VERSION SET pos = '2222' WHERE Id = 1";

        using (MySqlCommand cmd = new MySqlCommand(sql, cn))
        {
            var x = cmd.ExecuteNonQuery();
        }

        string sql_new = @"select * from TBL_VERSION WHERE Id = 1 LIMIT 1";

        using (MySqlCommand cmd = new MySqlCommand(sql_new, cn))
        {
            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                reader.Read();
                new_string = reader["pos"].ToString();
            }
        }
        cn.Close();
    }
    catch (Exception ex)
    {
        Console.Write(ex.Message);
    }
}

Then the database autocommit was set to 1, in the visual studio debugging the table was updated Ex. old_string = "5555" and new_string = "2222".

But if I try to check in other mysql client tools like SQLYog the record was not change when I try to run a same select statement, but if run the update statement direct to SQLYog, the record was successfully updated, then if I debug again the application the its already update.

Is any body encounter this problem?

0

There are 0 answers