I need to pass all the data from a DataGridView
to a database in MySQL, the only option to do is going through DataGrid
and inserting.
My previous code was:
foreach (DataGridViewRow dgvRenglon in dtaPagos.Rows)
{
MessageBox.Show(dgvRenglon.Cells[0].Value.ToString());
MessageBox.Show(dgvRenglon.Cells[1].Value.ToString());
MessageBox.Show(dgvRenglon.Cells[2].Value.ToString());
}
But it does not work for what I want or is wrong.
How can I go through the row of DataGrid
and get the data of each of them?
My DataGrid
Solution
for (int fila = 0; fila < dtaPagos.Rows.Count-1; fila++)
{
for (int col = 0; col < dtaPagos.Rows[fila].Cells.Count; col++)
{
string valor = dtaPagos.Rows[fila].Cells[col].Value.ToString();
MessageBox.Show(valor);
}
}