private void btnAceptar_Click(object sender, EventArgs e) { try { List <string> lista = new List <string>(); int i = 0; foreach (DataGridViewRow dgv in dataGridView1.Rows) { lista.Add(entidad + "." + "[" + dgv.Cells[0].Value + "]" + " " + dgv.Cells[1].Value + " " + "'" + dgv.Cells[2].Value.ToString() + "'" + " " + dgv.Cells[3].Value); } string query = string.Join(" ", lista.ToArray()); pasar(query); if (procesar.ExistenciaCampo("PKID", "filtro", " tabla = '" + entidad + "'")) { procesar.eliminar("Filtro", "tabla = '" + entidad + "'"); foreach (DataGridViewRow dgv in dataGridView1.Rows) { procesar.insertar("insert Filtro values(newid(),'" + dgv.Cells[0].Value + "','" + dgv.Cells[1].Value + "','" + dgv.Cells[2].Value.ToString() + "','" + dgv.Cells[3].Value + "','" + entidad + "','" + i + "')"); i++; } } else { foreach (DataGridViewRow dgv in dataGridView1.Rows) { procesar.insertar("insert Filtro values(newid(),'" + dgv.Cells[0].Value + "','" + dgv.Cells[1].Value + "','" + dgv.Cells[2].Value.ToString() + "','" + dgv.Cells[3].Value + "','" + entidad + "','" + i + "')"); i++; } } this.Close(); } catch (Exception t) { MessageBox.Show(t.Message); } }