private void button1_Click_1(object sender, EventArgs e) { var form = new AbForm(); var res = form.ShowDialog(); if (res == DialogResult.OK) { var fname = form.Name_.Text; var sname = form.sName.Text; var tname = form.tName.Text; var date = Convert.ToDateTime(form.Birthday.Text); var comment = form.Comment.Text; var addres = form.Address.Text; var connection = new SqlConnection(address_and_else); connection.Open(); var reqiest = "INSERT INTO Nazarov_Abonent (name,\"second name\", \"third name\", comment, address, birthday) VALUES ('" + fname + "' ,'" + sname + "' ,'" + tname + "' ,'" + comment + "' ,'" + addres + "' ,'" + date + "')"; var command = new SqlCommand(reqiest, connection); command.ExecuteNonQuery(); connection.Close(); UpdateAll(); } }
private void button2_Click_1(object sender, EventArgs e) { var rov = dgrv_contact.SelectedRows.Count > 0 ? dgrv_contact.SelectedRows[0] : null; if (rov == null) { MessageBox.Show("Строчку выбери", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var form = new AbForm(); form.Name_.Text = rov.Cells["name"].Value.ToString(); form.sName.Text = rov.Cells["second name"].Value.ToString(); form.tName.Text = rov.Cells["third name"].Value.ToString(); form.Comment.Text = rov.Cells["comment"].Value.ToString(); form.Address.Text = rov.Cells["address"].Value.ToString(); form.Birthday.Text = rov.Cells["birthday"].Value.ToString(); var res = form.ShowDialog(); if (res == DialogResult.OK) { var fname = form.Name_.Text; var sname = form.sName.Text; var tname = form.tName.Text; var comment = form.Comment.Text; var addres = form.Address.Text; var date = Convert.ToDateTime(form.Birthday.Text); var connection = new SqlConnection(address_and_else); var id = rov.Cells["Id"].Value.ToString(); connection.Open(); var reqiest = "UPDATE Nazarov_Abonent SET name ='" + fname + "', \"second name\"='" + sname + "', \"third name\"='" + tname + "', comment='" + comment + "', address='" + addres + "', birthday='" + date + "' WHERE Id=" + id + ";"; var command = new SqlCommand(reqiest, connection); command.ExecuteNonQuery(); connection.Close(); UpdateAll(); } }