I have to fill a table with the data from a DataGridView but I can not do it, I pass the data to a first DataGriView. All this with LINQ
After filling the first DataGriView I want the "Save Week" button to save the data in SQQL and show it in the second DataGriView (with show I have no problem). The code of the button is:
private void button2_Click(object sender, EventArgs e)
{
DataGridView Grid = dataGridView1;
for (int fila = 0; fila < Grid.Rows.Count - 1; fila++)
{
for (int col = 0; col < Grid.Rows[fila].Cells.Count; col++)
{
MenuporSemana ms = new MenuporSemana();
ms.Año = Convert.ToInt32(Grid.Rows[fila].Cells[col].Value.ToString());
ms.Semana = Convert.ToInt32(Grid.Rows[fila].Cells[col].Value.ToString());
ms.Dia = Grid.Rows[fila].Cells[col].Value.ToString();
ms.Sopa = Grid.Rows[fila].Cells[col].Value.ToString();
ms.Guisado = Grid.Rows[fila].Cells[col].Value.ToString();
Datos.MenuporSemana.InsertOnSubmit(ms);
Datos.SubmitChanges();
}
}
}
He had also tried to do it with Foreach and had it in the following way:
foreach (DataGridViewRow GVRow in dataGridView1.Rows)
{
MenuporSemana ms = new MenuporSemana();
ms.Año = Convert.ToInt32(dataGridView1.Cells[0].Value.ToString());
ms.Semana = Convert.ToInt32(GVRow.Cells[1].Value.ToString());
ms.Dia = GVRow.Cells[2].Value.ToString();
ms.Sopa = GVRow.Cells[3].Value.ToString();
ms.Guisado = GVRow.Cells[4].Value.ToString();
Datos.MenuporSemana.InsertOnSubmit(ms);
Datos.SubmitChanges();
}
But neither of the two worked and I would like to know how to implement that part or if there is another way to do it. Thanks.