0

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.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by YMCMb
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.