Hello

I seem to have a problem with a UPDATE that just does not want to work. Im simpled it down to the most simple UPDATE possible and it simply does not want to work. Here is the simple version:

public static string CambiarDatosUsuarios(string usuario,string contr,string pregunta,string respuesta,string correo)
    {
        string res;
        try
        {
            comando = new MySqlCommand("UPDATE usuario SET pregunta=@preg,respuesta=@resp,email=@cor WHERE nombreu=@usud", conexion);
            comando.Parameters.Add("@usud", MySqlDbType.VarChar, 50).Value = usuario.ToUpper();
            comando.Parameters.Add("@preg", MySqlDbType.VarChar, 50).Value = pregunta;
            comando.Parameters.Add("@resp", MySqlDbType.VarChar, 50).Value = respuesta.ToUpper();
            comando.Parameters.Add("@cor", MySqlDbType.VarChar, 50).Value = correo;
            AbrirConexion();
            comando.ExecuteNonQuery();
            comando.Parameters.Clear();
            comando.Dispose();
            res = "Usuario actualizado con excito";
        }
        catch (Exception ex)
        {

            res = ex.Message;
        }
        finally
        {
            CerrarConexion();
        }
        return res;
    }

It gives NO errors but doesnt UPDATE any columns. I replaced it with a SELECT COUNT(*) and it works perfectly so I know I dont have column names or the table wrong.

If someone could help, thanks alot.

Member Avatar for stbuchok

What is the data type of the column nombreu and is it the tables primary key.

Also please try to start using stored procedures as they help prevent SQL injections and make it easier to modify your SQL and help with modularity.

Also do the clearing of parameters and disposing in the finally block, if there is an error the finally block will normally still be executed.

Hmm i think if you tried using a BUSINESS LOGIC LAYER to update the information it will work better for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.