Sujeet Raman

Sujeet Raman

  • 861
  • 927
  • 354k

How to merge Multiple datatable in a single datatable

Feb 2 2022 2:49 PM

Hi,

i have 4 datatable. I need to make it one single table and I need to keep all duplicate columns also.Merge methode missing some data.I need to join all tables and to a single one and should keep duplicate columns also.I used below codes but i am missing some coloumn (duplicates also)

DataTable dtFinal = new DataTable();
for (int i = 0; i < resultDS.Tables.Count; i++)
{
    if (i == 0)
        dtFinal = resultDS.Tables[i].Copy();
    else
        dtFinal.Merge(resultDs.Tables[i]);
}
var ds = new DataSet();
ds.Tables.Add(dtFinal);

 


Answers (10)