My question is as follows: I have a gridview that I populate it with a data table of a table called "DiscountDate", however I need a button that when clicked it will go into another table named "sectors" and go through each row of the sectors table and then check if the sector found in the "sectors" table is already in the datagrid.
I've tried this, but I'm not experiencing success:
private void IncluiTodosSetores_Click(object sender, EventArgs e)
{
DataTable tabela = Dados.carregaSetoresTodos();
foreach (DataRow linha in tabela.Rows)
{
int achou = 0;
foreach (DataGridViewRow dataGridViewRow in GridDesconto.Rows)
{
int codorig = Convert.ToInt16(linha["Codigo"]);
int codgrid = Convert.ToInt16(dataGridViewRow.Cells["setor_codigo"].Value);
if (codorig.ToString() == codgrid.ToString())
{
achou = 1;
break;
}
else
{
achou = 0;
break;
}
}
if (achou == 0)
{
//inclui o setor nao encointrado no grid
}
}
}