private void userFormButton_Click(object sender, EventArgs e) { // Get user input. string uname = usernameTextBox.Text; string pwd = passwordTextBox.Text; // Setup Query, declare reader. string unameQuery = "SELECT userID, uName, uPassword FROM Users WHERE uName='" + uname + "' AND uPassword='******'"; OleDbDataReader reader; // Open connection. OleDbConnection connection = new OleDbConnection(connectionString); OleDbCommand command = new OleDbCommand(unameQuery, connection); connection.Open(); // Execute reader. reader = command.ExecuteReader(); // If user exists. if (reader.HasRows) { reader.Read(); string uid = reader["userID"].ToString(); reader.Close(); connection.Close(); this.Hide(); UserApplication.UserForm userForm = new UserApplication.UserForm(int.Parse(uid)); userForm.Show(); } // No such user. else { MessageBox.Show("Wrong username/password combination!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void guestButton_Click(object sender, EventArgs e) { this.Hide(); UserApplication.UserForm userForm = new UserApplication.UserForm(9999); userForm.Show(); }