Access Restriction, in Design of Visual Studio,com C#!

Asked

Viewed 147 times

1

During my computer technical course, in the Programming module, I did a project with Windows Form! This project is linked to a database created by myself in SQL Server!

It would be a "software" for medical clinic (all fictitious), at first I have a screen where who accesses will put: User, Password and Performance Sector! There are only three sectors that can access the system: Doctors, Administrator and Receptionist! Since each one will have different access, ie the Adm is who can access the entire system,ja doctors and receptionist will be denied access to some areas!

I made a DAL and also made the button codes that will allow access to the system! Only he gives me an error message: Errooo

The problem is I can’t find the mistake! Follow below image of the code:

inserir a descrição da imagem aqui

Unfortunately I’ll have to put the code in anyway, because I can’t get a print of the entire code,!

**

}
            dr.Close();
            return seto.SetorRestricao;
           }
               public string logasenha(string usuarioRestricao,string senhaRestricao,string setoAtu)
               {
                  SqlConnection NanoTec = new SqlConnection(Conexao.ObtemConexao());
                  NanoTec.Open();
                  SqlCommand Comando = new SqlCommand("select * from Restricao where NomeUsuario = '" + usuarioRestricao + "' , SenhadeAcesso = '" + senhaRestricao + "' AND SetorAtuacao = '" + setoAtu + "'" , NanoTec);
                  SqlDataReader dr = Comando.ExecuteReader();
                   RestricaoDAL senha = new RestricaoDAL();
                     while (dr.Read())
                     {
                        senha.SenhaRestricao = dr["SenhaRestricao"].ToString();
                        }
                            return senha.SenhaRestricao;
            }
    }
}

**

Anyone to help? After this help I will need another, but I will not post it until I find my mistake clear!

Thank you Carol!

  • Exchange the comma in consultation for an AND

  • Assim: SqlCommand Comando = new SqlCommand("select * from Restricao where NomeUsuario = '" + usuarioRestricao + "' AND SenhadeAcesso = '" + senhaRestricao + "' AND SetorAtuacao = '" + setoAtu + "'" , NanoTec);

  • 1

    Denis Rudnei, thank you so much for your help! I tidied up the code and gave it right!

  • 1

    http://meta.pt.stackoverflow.com/a/5485/55024

1 answer

2


Your problem is a sql syntax error.

Change the line;

SqlCommand Comando = new SqlCommand("select * from Restricao where NomeUsuario = '" + usuarioRestricao + "' , SenhadeAcesso = '" + senhaRestricao + "' AND SetorAtuacao = '" + setoAtu + "'" , NanoTec);

To;

SqlCommand Comando = new SqlCommand("select * from Restricao where NomeUsuario = '" + usuarioRestricao + "' and SenhadeAcesso = '" + senhaRestricao + "' AND SetorAtuacao = '" + setoAtu + "'" , NanoTec);

Browser other questions tagged

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