//Student private void Add_Click(object sender, RoutedEventArgs e) { int group; if (int.TryParse(GroupBox.Text, out group)) { } else { MessageBox.Show("You have entered a wrong data"); } if (GroupBox.Text == "" || StudentNameBox.Text == "" || HometownBox.Text == "") { MessageBox.Show("Fill in all data and continue"); } else { string ConnectionString = @"Data Source=DESKTOP-R0R983R;Initial Catalog=ADO.NET;Integrated Security=True"; using (SqlConnection cn = new SqlConnection(ConnectionString)) { cn.Open(); SqlTransaction transaction = cn.BeginTransaction(); SqlCommand command = cn.CreateCommand(); command.Transaction = transaction; try { command.CommandText = $"INSERT INTO STUDENT (IDGROUP, NAME, HOMETOWN) VALUES ({group}, '{name}', '{hometown}');"; command.ExecuteNonQuery(); transaction.Commit(); MessageBox.Show("Object has been added"); } catch (Exception ex) { MessageBox.Show(ex.Message); transaction.Rollback(); } } GroupBox.Clear(); StudentNameBox.Clear(); HometownBox.Clear(); } }