Search code examples
c#.netado.netdatatabledataadapter

Insert rows to DataTable from SQL table


I have a Datatable in my C# program that I would like to INSERT rows from a temp table in SQL Server. The dataAdapter.FILL() method writes over the whole datatable. I need to keep the records that are in the DataTable and add records that exist in the temp table back into my DataTable.

I do not see a DA method for that, they all seem to go back to the SQL Server table except FILL. Is this possible?


Solution

  • How about Merging your DataTables

    DataTable dttemp = new DataTable();
    
    dataAdapter.Fill(dtTemp);
    
    originaldatatable.Merge(dtTemp);