Form de Login @Perfil não tem valor padrão

.NET

13/10/2013

Olá pessoal, tenho um windowsform de login onde estou implementando a verificação de perfil para restringir acessos ao usuário, só que nesta implementação está dando o seguinte erro "O parâmetro @Perfil não tem valor padrão.", como é o meu primeiro projeto...preciso de mais ajuda, aqui o código atual :

public partial class FrmLogin : Form
    {
        //responsavel pelo nivel de acesso
        public static string NivelAcesso;
        //responsavel por mostrar quem está conectado
        public static string usuarioConectado;
        //responsavel por mostrar a senha para o alerta.
        public static string senhaUsuario;

        public static string conexao;

        public FrmLogin()
        {
            InitializeComponent();
        }
             
        private void FrmLogin_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'bDBiblioteca2DataSet.Perfil' table. You can move, or remove it, as needed.
            this.perfilTableAdapter.Fill(this.bDBiblioteca2DataSet.Perfil);
            // TODO: This line of code loads data into the 'bDBiblioteca2DataSet.Funcionario' table. You can move, or remove it, as needed.
            this.funcionarioTableAdapter.Fill(this.bDBiblioteca2DataSet.Funcionario);
        }
        private void BtnEntrar_Click(object sender, EventArgs e)
        {
            try
            {
                if ((textBox1.Text != "") && (textBox2.Text != ""))
                {
                    OleDbConnection conexao = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Application.StartupPath + "\\BDBiblioteca2.mdb");
                   
                    OleDbCommand comando = new OleDbCommand("Select * From Funcionario Where Login = @Login  And " + "Senha = @Senha And Perfil = @Perfil ", conexao);
                                        
                    comando.Parameters.Add("@Login ", OleDbType.VarChar).Value = textBox1.Text;
                    comando.Parameters.Add("@Senha", OleDbType.VarChar).Value = textBox2.Text;
                    comando.Parameters.Add("@Perfil", OleDbType.VarChar).Value = NivelAcesso;
                                        
                    conexao.Open();
                    OleDbDataReader reader = null;
                  
                    reader = comando.ExecuteReader();
                   
                    if (reader.Read())
                    {
                         usuarioConectado = textBox1.Text;
                        
                        senhaUsuario = textBox2.Text;
                        
                        FrmPrincipal frmp = new FrmPrincipal();
                        frmp.Show();
                        this.Visible = false;
                    }
Jair Souza

Jair Souza

Curtidas 0

Respostas

Gustavo Cardoso

Gustavo Cardoso

13/10/2013

tenta colocar
NivelAcesso = "2"; ou "1" , porque você definiu a string, mais não colocou valor nela..
GOSTEI 0
Jair Souza

Jair Souza

13/10/2013

Resolvido :

private void BtnEntrar_Click(object sender, EventArgs e)
        {
            try
            {
                if ((textBox1.Text != "") && (textBox2.Text != ""))
                {
                    OleDbConnection conexao = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Application.StartupPath + "\BDBiblioteca2.mdb");
 
                    OleDbCommand comando = new OleDbCommand("SELECT F.Perfil, P.Descricao FROM Funcionario AS F " + " INNER JOIN Perfil AS P ON F.Perfil = P.IDPerfil Where F.Login = @Login And F.Senha = @Senha", conexao);
 
                    comando.Parameters.Add("@Login ", OleDbType.VarChar).Value = textBox1.Text;
                    comando.Parameters.Add("@Senha", OleDbType.VarChar).Value = textBox2.Text;
 
                    conexao.Open();
 
                    OleDbDataReader reader = null;
 
                    reader = comando.ExecuteReader(CommandBehavior.CloseConnection);
       
                if (reader.HasRows)
 
                    while(reader.Read())
                    {
                        NivelAcesso = (reader["Descricao"].ToString());
                         
                        usuarioConectado = textBox1.Text;
                        senhaUsuario = textBox2.Text;
 
                        FrmPrincipal frmp = new FrmPrincipal();
                        frmp.NivelAcesso = Convert.ToString(NivelAcesso);
                        frmp.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("Usuário ou Senha Inválido !", "Acesso", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        textBox1.Clear();
                        textBox2.Clear();
                        textBox1.Focus();
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


**No FrmPrincipal :


GOSTEI 0
POSTAR