Question: I have the following problem when inserting the info in the databases

```
public void Insertar()
{
   SqlConnection con = new SqlConnection();
   con.ConnectionString = "Data Source=BD-DLLO-SP2016;Initial Catalog=GobernacionCesar;Integrated Security=True";

   con.Open();

   string query = "INSERT INTO Liquidacion (IdLiquidacion, IdPeriodo, FechaGeneracion, Usuario) VALUES(@IdLiquidacion, @IdPeriodo, @FechaGeneracion, @Usuario)";

   SqlCommand com1 = new SqlCommand(query, con);

   foreach (GridViewRow gridRow in GridView4.Rows)
   {
       Iniciar();
       com1.Parameters.AddWithValue("@IdLiquidacion", A);
       com1.Parameters.AddWithValue("@IdPeriodo", cell);
       com1.Parameters.AddWithValue("@FechaGeneracion", DateTime.Now.ToString());
       com1.Parameters.AddWithValue("@Usuario", gridRow.Cells[0].Text);

       com1.ExecuteNonQuery();
   }

   con.Close();
   return;
}

```

Answer: 
You should 

* **define** the parameters **outside** of the loop
* only **set** the values for the parameters inside the loop

Like this:

```
SqlCommand com1 = new SqlCommand(query, con);

// define parameters - you need to adapt the datatypes - I was only guessing
com1.Parameters.Add("@IdLiquidacion", SqlDbType.Int);
com1.Parameters.Add("@IdPeriodo", SqlDbType.VarChar, 50);
com1.Parameters.Add("@FechaGeneracion", SqlDbType.DateTime);
com1.Parameters.Add("@Usuario", SqlDbType.VarChar, 100);

foreach (GridViewRow gridRow in GridView4.Rows)
{
   Iniciar();

   // inside the loop, only SET the values
   com1.Parameters["@IdLiquidacion"].Value = A;
   com1.Parameters["@IdPeriodo"].Value = cell;
   com1.Parameters["@FechaGeneracion"].Value = DateTime.Now;
   com1.Parameters["@Usuario"].Value = gridRow.Cells[0].Text;

   com1.ExecuteNonQuery();
}

```
You're adding the parameters in the loop. If you clear them before adding, this should work.