Login authorization

Asked

Viewed 34 times

-1

Guys I have access authorization login, only when I execute the authorization it deletes the previous one and stays the current one. For example: I have the user login (basic), to execute an action the user needs to be released by a login (Administrator). I am doing this code below. But when I run it , it is logged in as Login (Administrator) and no longer as login (basic).

if (LoginUsuárioCache.Cargo == FuncionárioCargo.Administrador)
{
    ConexaoLeituraBanco conexaoLeituraBanco = new ConexaoLeituraBanco();
    using (var connection = conexaoLeituraBanco.GetConnection())
    {
       connection.Open();
       using (MySqlCommand commad = new MySqlCommand())
       {                                    
            commad.Connection = connection; 
            commad.CommandText = "UPDATE pdv_historico SET sangria = sangria"; 
            commad.Parameters.AddWithValue("sangria", sangria);
            commad.CommandType = CommandType.Text;
            MySqlDataReader reader = commad.ExecuteReader();
            connection.Close();
            this.Close();
       }                                                               
    }
}                                   

         

1 answer

0

Your UPDATE does not have WHERE. This affects all table records.

"UPDATE pdv_historico SET sangria = sangria"

You should check according to your logic, and pass the appropriate ID (or other field) as clause. Exemplifying in a very basic way:

SqlParameter param  = new SqlParameter();
param.ParameterName = "@IdUsuario";
param.Value         = usuario.Id;

"UPDATE pdv_historico SET sangria = sangria WHERE IDUsuario=@IdUsuario"
  • The update part is correct. I already put the WHERE. It does the UPDATE values correctly. The problem is that it comes back logged in as Administrator and not as it was before. As login (basic).

  • How’s the rest of your code?

  • UPDATE pdv_historico SET sangria = @ sangria WHERE usuario = '" + txtNome.Text + "' ORDER BY idpdv_historico DESC LIMIT 1"; Then it makes the change in mysql where the basic user name is equal to (txtNome.text). Then close the connection, close the login tele and return to the initial FORM.

Browser other questions tagged

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