How to insert a Datarow in the middle of a Datatable

Asked

Viewed 29 times

0

I need to give an Insertat of a Datarow in the middle of a Datatable, but the way I’m always making the error "This line already belongs to another table"

DataTable subpedido = Pedido_FichaTecnicaDAO.PegarInstancia().ConsultarPedidoID(Convert.ToInt32(this.gridPedidos.Rows[e.RowIndex].Cells[1].Value));
DataTable dataTable = (DataTable)gridPedidos.DataSource;
for (int i = 0; i <= subpedido.Rows.Count - 1; i++)
{
    DataRow row = subpedido.Rows[i];
    dataTable.Rows.InsertAt(row, e.RowIndex + 1);
}
  • Maybe because of the reference, I think you need to create a new Row and do the "to" of the columns and their values.

  • Managed to solve? maybe with a cast also work

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.