Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            strSql = "select * from Usuarios where Login like @Login and Senha = @Senha";

            sqlCon = new SqlConnection(strCon);
            SqlCommand comando = new SqlCommand(strSql, sqlCon);

            comando.Parameters.AddWithValue("@Login", SqlDbType.VarChar).Value = txt_login.Text;
            comando.Parameters.AddWithValue("@Senha", SqlDbType.VarChar).Value = txt_senha.Text;
            comando.Connection = sqlCon;
            sqlCon.Open();

            DataSet        ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(comando);

            da.Fill(ds);
            sqlCon.Close();

            bool loginSuccessful = ((ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0));

            if (loginSuccessful)
            {
                MessageBox.Show("Login efetuado com sucesso!");

                Cadastro cad = new Cadastro();
                LogMenu  log = new LogMenu();
                this.Hide();
                cad.ShowDialog();
            }
            else
            {
                MessageBox.Show("Usuário ou Senha incorretos!");
            }
        }
        private void voltarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LogMenu log = new LogMenu();

            this.Hide();
            log.ShowDialog();
        }