85
{
InitializeComponent();
con.Open();
SqlCommand cmdRead = new SqlCommand();
cmdRead.Connection = con;
cmdRead.CommandText = "SELECT p_Name FROM Post";
SqlDataReader reader = cmdRead.ExecuteReader();
while (reader.Read())
{
cmbPost.Items.Add(reader[0].ToString());
}
reader.Close();
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (txtSecondName.Text == "" || txtFirstName.Text == ""
|| txtMidName.Text == "" || txtID.Text == ""
|| txtBurthday.Text == "" || txtAccount.Text == "")
{
MessageBox.Show("Не задано значение");
}
else
{
con.Open();
SqlCommand cmdWrite = new SqlCommand();
cmdWrite.Connection = con;
cmdWrite.CommandText = "INSERT INTO [Employer] (emp_LastName,
emp_FirstName, emp_MidName, emp_Birthday, emp_ID, emp_Account, id_Post) VALUES
(@LastName, @FirstName, @MidName, @Birthday, @ID, @Account, @Post)";
cmdWrite.Parameters.AddWithValue("LastName", txtSecondName.Text);
cmdWrite.Parameters.AddWithValue("FirstName", txtFirstName.Text);
cmdWrite.Parameters.AddWithValue("MidName", txtMidName.Text);
cmdWrite.Parameters.AddWithValue("Birthday", txtBurthday.Text);
cmdWrite.Parameters.AddWithValue("ID", txtID.Text);
cmdWrite.Parameters.AddWithValue("Account", txtAccount.Text);
cmdWrite.Parameters.AddWithValue("Post", cmbPost.SelectedIndex+1);
cmdWrite.ExecuteNonQuery();
con.Close();
}
}
}
}
using System;