help
Root Question Message
private void dataGridViewAcoesPendentes_CellClick_2(object sender, DataGridViewCellEventArgs e)
{
if (dataGridViewAcoesPendentes.Columns[e.ColumnIndex].HeaderText == "BtnEditar")
{
int id;
id = Convert.ToInt32(dataGridViewAcoesPendentes.Rows[e.RowIndex].Cells["acaoID"].Value);
con.Open();
try
{
SqlCommand cmd = new SqlCommand("UPDATE tbl_acoes SET estado = 'Validado'", con);
int result = cmd.ExecuteNonQuery();
if (result > 0)
{
MessageBox.Show("Ação Validado");
SqlCommand cmd2 = new SqlCommand("SELECT * FROM tbl_acoes WHERE estado = 'pendente'", con);
DataTable dt = new DataTable();
dt.Load(cmd2.ExecuteReader());
dataGridViewAcoesPendentes.DataSource = dt;
con.Close();
}
else
{
MessageBox.Show("Ensaio nao validado!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
}
id
meant to represent the row's identifying acaoID
acaoID
, you need to use it in the UPDATE
statementid
tbl_acoes
con.Open();
private void LoadAcoesPendentes()
{
SqlConnection con = new SqlConnection("Data Source=mydatasource");
SqlCommand cmd2 = new SqlCommand("SELECT * FROM tbl_acoes WHERE estado='Pendente'", con);
/*SqlCommand cmd2 = new SqlCommand("SELECT * FROM tbl_ensaios WHERE idProjetos =" + txtIdFerramenta.Text + "", con);*/
con.Open();
DataTable dt = new DataTable();
dt.Load(cmd2.ExecuteReader());
dataGridViewAcoesPendentes.DataSource = dt;
con.Close();
}
dt.Load....
what kind of values can you seeacaoID
of the row that you clickeddataGridViewAcoesPendentes
is what's being populated theredataGridViewAcoesPendentes_CellClick_2
handler, you should be able to get the data inside the selected rowdt
in your LoadAcoesPendentes
methoddataGridViewAcoesPendentes
SqlCommand cmd = new SqlCommand("UPDATE tbl_acoes SET estado = 'Validado'", con);
private void dataGridViewAcoesPendentes_CellClick_2(object sender, DataGridViewCellEventArgs e)
{
if (dataGridViewAcoesPendentes.Columns[e.ColumnIndex].HeaderText == "BtnEditar")
{
int id;
id = Convert.ToInt32(dataGridViewAcoesPendentes.Rows[e.RowIndex].Cells["acaoID"].Value);
con.Open();
try
{
SqlCommand cmd = new SqlCommand("UPDATE tbl_acoes SET estado = 'Validado'", con);
int result = cmd.ExecuteNonQuery();
if (result > 0)
{
MessageBox.Show("Ação Validado");
SqlCommand cmd2 = new SqlCommand("SELECT * FROM tbl_acoes WHERE estado = 'pendente'", con);
DataTable dt = new DataTable();
dt.Load(cmd2.ExecuteReader());
dataGridViewAcoesPendentes.DataSource = dt;
con.Close();
}
else
{
MessageBox.Show("Ação nao validada!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
}