private void editGoodsToolStripMenuItem1_Click(object sender, EventArgs e) { EditGoods newForm = new EditGoods(); newForm.Owner = this; newForm.Show(); }
private void button1_Click(object sender, EventArgs e) { SqlConnectionStringBuilder connect = new SqlConnectionStringBuilder(); connect.InitialCatalog = "kleinkind"; connect.DataSource = @"ALEKSEY-PC"; connect.ConnectTimeout = 30; connect.IntegratedSecurity = true; using (SqlConnection cn = new SqlConnection()) { cn.ConnectionString = connect.ConnectionString; try { SqlCommand myCommand = new SqlCommand("Add_Goods", cn); myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.AddWithValue("@Name", comboBox1.Text); myCommand.Parameters.AddWithValue("@Category", comboBox2.Text); myCommand.Parameters.AddWithValue("@Color", comboBox3.Text); myCommand.Parameters.AddWithValue("@Size", comboBox4.Text); myCommand.Parameters.AddWithValue("@Count", Convert.ToInt32(textBox1.Text)); myCommand.Parameters.AddWithValue("@Unit", comboBox5.Text); myCommand.Parameters.AddWithValue("@Link", comboBox6.Text); cn.Open(); myCommand.ExecuteNonQuery(); } catch (FormatException ex) { MessageBox.Show("Вы ввели недопустимое значение"); } catch (SqlException ex) { // Протоколировать исключение MessageBox.Show(ex.Message); } finally { // Гарантировать освобождение подключения cn.Close(); } } comboBox1.Text = ""; comboBox2.Text = ""; comboBox3.Text = ""; comboBox4.Text = ""; textBox1.Text = ""; comboBox5.Text = ""; comboBox6.Text = ""; // EventOK(); EditGoods main = this.Owner as EditGoods; main.ReLoad(); Close(); }