using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace hospital { public partial class admin : Form { SqlConnection sqlConnection = null; public admin() { InitializeComponent(); } private void admin_Load(object sender, EventArgs e) { FormCreating.openConnection(ref sqlConnection); SqlDataAdapter dataAdapter = new SqlDataAdapter($"select * from employees", sqlConnection); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); dataGridView1.DataSource = dataSet.Tables[0]; SqlCommand a = new SqlCommand($"select name_post from posts", sqlConnection); SqlDataReader reader = a.ExecuteReader(); while (reader.Read()) { comboBox1.Items.Add(reader.GetString(0)); } reader.Close(); } private void button1_Click(object sender, EventArgs e) { if (!comboBox1.Text.Equals("")) { string row = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString(); SqlCommand b = new SqlCommand($"select id_post from posts where name_post like N'{comboBox1.SelectedItem}'", sqlConnection); SqlCommand a = new SqlCommand($"update employees set id_post = @id_post where id_employee like {row}", sqlConnection); a.Parameters.AddWithValue("id_post", b.ExecuteScalar().ToString()); a.ExecuteNonQuery(); SqlDataAdapter dataAdapter = new SqlDataAdapter($"select * from employees", sqlConnection); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); dataGridView1.DataSource = dataSet.Tables[0]; } else { MessageBox.Show("Ошибка", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void admin_FormClosing(object sender, FormClosingEventArgs e) { Application.Exit(); } } }