private async void simpleButton1_Click(object sender, EventArgs e) { /// using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { string pass = null; sqlConnection.Open(); SqlDataReader sqlReader = null; SqlCommand command; command = new SqlCommand("CheckAdmins", sqlConnection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("login", SqlDbType.NVarChar).Value = textBox1.Text.Trim(); try { sqlReader = await command.ExecuteReaderAsync(); while (await sqlReader.ReadAsync()) { pass = Convert.ToString(sqlReader["pas"]); } if (textBox2.Text == pass) { if ((!string.IsNullOrEmpty(textBox3.Text) && !string.IsNullOrWhiteSpace(textBox3.Text) && !string.IsNullOrEmpty(textBox4.Text) && !string.IsNullOrWhiteSpace(textBox4.Text))) { Task task = new Task(UpdateAdmin); task.Start(); task.Wait(); this.Close(); XtraForm2 xtraForm2 = new XtraForm2(); xtraForm2.Show(); } else { MessageBox.Show("Заповніть всі поля!", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { textBox2.Text = ""; MessageBox.Show("Введено неправильні облікові дані.", "Увага", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { //MessageBox.Show("Введено неправильні облікові дані.", "Увага", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { if (sqlReader != null) { sqlReader.Close(); } } } }
private async void simpleButton1_Click(object sender, EventArgs e) { String login = textBox1.Text; String password = textBox2.Text; using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { string pass = null; sqlConnection.Open(); SqlDataReader sqlReader = null; SqlCommand command; command = new SqlCommand("CheckAdmins", sqlConnection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("login", SqlDbType.NVarChar).Value = textBox1.Text.Trim(); try { sqlReader = await command.ExecuteReaderAsync(); while (await sqlReader.ReadAsync()) { pass = Convert.ToString(sqlReader["pas"]); } if (textBox2.Text == pass) { XtraForm2 xtraForm2 = new XtraForm2(); xtraForm2.Show(); } else { textBox2.Text = ""; MessageBox.Show("Введено неправильні облікові дані.", "Увага", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { //MessageBox.Show("Введено неправильні облікові дані.", "Увага", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { if (sqlReader != null) { sqlReader.Close(); } } } }