Search code examples
.netado.netsystem.data.datatable

Creating Disconnected DataRows in .NET


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)


Solution

  • 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.