private void button1_Click(object sender, EventArgs e) { String username; username = comboBox1.SelectedItem.ToString(); File.WriteAllText("System.FileType.txt", username); MessageBox.Show("Welcome, " + username.Trim()); SystemApplication sa = new SystemApplication(); sa.ShowDialog(); return; }
private void connection() { string connectionString = ("Server=localhost;user id=db_user;password=microsoft;Database=traininglog;"); MySqlConnection con = new MySqlConnection(connectionString); string userscript = "SELECT password FROM table_one WHERE username='******';"; MySqlCommand command = new MySqlCommand(userscript, con); con.Open(); if (username.Text == "administrator") { MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (reader["password"].ToString() == password.Text.Trim()) { File.WriteAllText("System.FileType.txt", username.Text); MessageBox.Show("Welcome, " + username.Text.Trim()); Form form3 = new Form3(); form3.ShowDialog(); return; } } } else { MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (reader["password"].ToString() == password.Text.Trim()) { File.WriteAllText("System.FileType.txt", username.Text); MessageBox.Show("Welcome, " + username.Text.Trim()); SystemApplication sa = new SystemApplication(); sa.ShowDialog(); return; } } } MessageBox.Show("Sorry, You have entered incorrect login information."); }