private void Button2_Click(object sender, EventArgs e) { try { if (!verificaCampos()) { MessageBox.Show("Preencha todos os campos!"); } else { if (MessageBox.Show("Deseja alterar o dado de locação de ID:" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + " ??" , "Alterar Locação", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { Locacao objl = new Locacao { locacao_id = (int)dataGridView1.CurrentRow.Cells[0].Value, locacao_tipo = txt_tipo.Text, locacao_valor = double.Parse(txt_valor.Text), locacao_dt_inicio = Convert.ToDateTime(txt_inicio.Text), locacao_dt_fim = Convert.ToDateTime(txt_fim.Text), automovel = (int)cb_carro.SelectedValue, cliente = (int)cb_carro.SelectedValue, funcionario = (int)cb_funcionario.SelectedValue }; LocacaoDAO ldao = new LocacaoDAO(); ldao.altera(objl); Uc_locacao_Load(null, null); } } } catch (Exception) { MessageBox.Show("Erro ao alterar o funcionario"); } }