private void Edit_abonent_Click_1(object sender, EventArgs e) { var row = DATA_Abonent.SelectedRows.Count > 0 ? DATA_Abonent.SelectedRows[0] : null; if (row != null) { Add_abonent form = new Add_abonent(); form.textBox_name.Text = row.Cells["Name_Abonent"].Value.ToString(); form.textBox_surname.Text = row.Cells["Surname_Abonent"].Value.ToString(); form.textBox_tarif.Text = row.Cells["Tarif"].Value.ToString(); form.textBox_start.Text = row.Cells["Date_Registration"].Value.ToString(); form.textBox_period.Text = row.Cells["Period_Dogovor"].Value.ToString(); if (form.ShowDialog() == DialogResult.OK) { var connection = new SqlConnection(connectionStr); connection.Open(); var req = "UPDATE Biling_abonent SET Name_Abonent = '" + form.textBox_name.Text + "', Surname_Abonent = '" + form.textBox_surname.Text + "', Tarif = '" + form.textBox_tarif.Text + "', Date_Registration = '" + form.textBox_start.Text + "', Period_Dogovor = ' " + form.textBox_period.Text + "'WHERE Id_Abonent = '" + row.Cells["Id_Abonent"].Value.ToString() + "'"; var command = new SqlCommand(req, connection); command.ExecuteNonQuery(); UpdateAbonentDgv(); } } }
private void Add_abonent_Click(object sender, EventArgs e) { Add_abonent form = new Add_abonent(); if (form.ShowDialog() == DialogResult.OK) { var connection = new SqlConnection(connectionStr); connection.Open(); var req = "INSERT INTO Biling_abonent (Name_Abonent, Surname_Abonent, Biling_abonent.Tarif, Date_Registration, Period_dogovor) VALUES ('" + form.textBox_name.Text + "', '" + form.textBox_surname.Text + "', '" + form.textBox_tarif.Text + "', '" + form.textBox_start.Text + "', '" + form.textBox_period.Text + "');"; var command = new SqlCommand(req, connection); command.ExecuteNonQuery(); UpdateAbonentDgv(); } }