What’s wrong with my Update?

Asked

Viewed 63 times

0

Good morning.

I’m a beginner and I’m having problems with my Update. I wonder what I’m doing wrong.

    public string Update(Usuario usuario)
    {
        var sql = new StringBuilder();

        sql.Append("UPDATE TBUSU SET " + Environment.NewLine);

        sql.Append($" SENHA     = '{usuario.Senha}' ");
        sql.Append($" ,EMAIL    = '{usuario.Email}' ");
        sql.Append($" ,TELEFONE = {usuario.Telefone} ");
        sql.Append($" ,STATUS   = '{(int)usuario.Status}' ");
        sql.Append($" ,FUNCAO   = '{(int)usuario.Funcao}' ");
        sql.Append("   WHERE    " + Environment.NewLine);
        sql.Append($"  NOME     = '{usuario.Nome}' ");


        var ret = Conexao.ExecutarComando(sql.ToString());

        return ret;
    }
  • 1

    I do not know if it is really necessary to use quotes, but in the phone you did not use, for example. You instead of using var ret can directly use return Conexao.ExecutarComando(sql.ToString());. Try to see sql.Tostring() output as well and see how the string looks.

  • 4

    A lot, especially a serious security problem. Correct: https://answall.com/q/202903/101 See tb https://answall.com/q/183975/101

  • Problems have several, as mentioned by Maniero... But what error are you getting?

  • It is not updating. Does not show error.

  • So... it could be yours ExecutarComando() or simply not finding any user as given name.

  • Edit the question by presenting the changed code with the Maniero recommendations

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.