예제 #1
0
        private void cmdReadLogIn_Click(object sender, EventArgs e)
        {
            string cmdString = "SELECT user_name, pass_word, faculty_id, student_id FROM LogIn ";
            cmdString += "WHERE (user_name=@name ) AND (pass_word=@word)";

            SqlCommand sqlCommand = new SqlCommand();
            SelectionForm selForm = new SelectionForm();
            SqlDataReader sqlDataReader;

            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.CommandText = cmdString;
            sqlCommand.Parameters.Add("@name", SqlDbType.Char).Value = txtUserName.Text;
            sqlCommand.Parameters.Add("@word", SqlDbType.Char, 8).Value = txtPassWord.Text;
            sqlDataReader = sqlCommand.ExecuteReader();
            if (sqlDataReader.HasRows == true)
            {
                //MessageBox.Show("LogIn is successful");
                selForm.Show();
                this.Hide();
            }
            else
                MessageBox.Show("No matched username/password found!");

            sqlCommand.Dispose();
            sqlDataReader.Close();
        }
예제 #2
0
        private void cmdTabLogIn_Click(object sender, EventArgs e)
        {
            string cmdString = "SELECT user_name, pass_word, faculty_id, student_id FROM LogIn ";
            cmdString += "WHERE (user_name=@name ) AND (pass_word=@word)";

            SqlDataAdapter LogInDataAdapter = new SqlDataAdapter();
            DataTable sqlDataTable = new DataTable();
            SqlCommand sqlCommand = new SqlCommand();
            SelectionForm selForm = new SelectionForm();

            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.CommandText = cmdString;
            sqlCommand.Parameters.Add("@name", SqlDbType.Char).Value = txtUserName.Text;
            sqlCommand.Parameters.Add("@word", SqlDbType.Char, 8).Value = txtPassWord.Text;
            LogInDataAdapter.SelectCommand = sqlCommand;
            LogInDataAdapter.Fill(sqlDataTable);
            if (sqlDataTable.Rows.Count > 0)
            {
                //MessageBox.Show("LogIn is successful");
                selForm.Show();
                this.Hide();
            }
            else
                MessageBox.Show("No matched username/password found!");
            sqlDataTable.Dispose();
            sqlCommand.Dispose();
            LogInDataAdapter.Dispose();
        }