2

How do you create DataRow instances that aren't tied to any particular DataTable instance?

(EDIT: I know you can create DataRows using the DataTable.NewRow() method, but the problem is that I can't seem to disconnect the row from its parent table so I can pass the individual row around without having to pass the entire table around)

madth3
  • 7,275
  • 12
  • 50
  • 74
plaureano
  • 3,139
  • 6
  • 30
  • 29

2 Answers2

1

One thing you could try is deleting it immediately:

DataRow row = table.NewRow();
row.Delete();

That will put it in a DataRowState of Detached, which sounds like what you want. I'm not sure what you're trying to achieve in terms of a bigger picture though, so this may not help.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

I rather would only copy the content of the DataRow. You can achive that with:

row.ItemArray

I think that would be a better approch, than trying to get a workaround for the lacking copy functionality.

BitKFu
  • 3,649
  • 3
  • 28
  • 43