Datatable Merge IN C#.Net
-
Hi All, I have two datatables, one datatable named "dtRecords1" gets filled from excel sheet, having column name "Name","Category", and on run time i have added a Identity column to "dtRecords1". Second Column gets filled from sql server database having three columsn "ID as Identity","Name","Category". Now i want to merge these two tables, i want this result from merge. If there are some changes in first datatable, depending upon all columns (comparing all column values) and ID Is same,it should be overwrited, and if there are some new rows these also should be added to the resulted database. Example: Datatable1 from excel ID,Name,Categoey 1,adnan,SE 2,ali,SSE 3,Imran,JSE Datatable2 From SQL Server DB ID,Name,Category 1,adnan,SSE 2,ali,SSE Resulted Datatable ID,Name,Category 1,adnan,SE -Changed ROw 2,ali,SSE -Unchanged Row 3,Imran,JSE - Newly added Row Many THanks & Best Regards, adnan
Many Thanks, Adnan Rafiq muhammadadnanrafiq@gmail.com
-
Hi All, I have two datatables, one datatable named "dtRecords1" gets filled from excel sheet, having column name "Name","Category", and on run time i have added a Identity column to "dtRecords1". Second Column gets filled from sql server database having three columsn "ID as Identity","Name","Category". Now i want to merge these two tables, i want this result from merge. If there are some changes in first datatable, depending upon all columns (comparing all column values) and ID Is same,it should be overwrited, and if there are some new rows these also should be added to the resulted database. Example: Datatable1 from excel ID,Name,Categoey 1,adnan,SE 2,ali,SSE 3,Imran,JSE Datatable2 From SQL Server DB ID,Name,Category 1,adnan,SSE 2,ali,SSE Resulted Datatable ID,Name,Category 1,adnan,SE -Changed ROw 2,ali,SSE -Unchanged Row 3,Imran,JSE - Newly added Row Many THanks & Best Regards, adnan
Many Thanks, Adnan Rafiq muhammadadnanrafiq@gmail.com
I don't think there is a merge method in the DataTable class, there is in DataSet though if all else fails. I'm sure you could use importrow though like so:
for (int x = 0; x < datatable2.Rows.Count; x++)
{
datatable1.ImportRow(datatable2.Rows[x])
}There are 10 types of people in the world, those who understand binary and those who dont.
-
I don't think there is a merge method in the DataTable class, there is in DataSet though if all else fails. I'm sure you could use importrow though like so:
for (int x = 0; x < datatable2.Rows.Count; x++)
{
datatable1.ImportRow(datatable2.Rows[x])
}There are 10 types of people in the world, those who understand binary and those who dont.
I am 100% sure there is method merge in datatable, when i create instance of datatable, press dot, you will also see, merge method. Will you please help to fullfill the requirment that i have asked in question or explain what you have in this loop. Many Thanks, adnna
Many Thanks, Adnan Rafiq muhammadadnanrafiq@gmail.com
-
I am 100% sure there is method merge in datatable, when i create instance of datatable, press dot, you will also see, merge method. Will you please help to fullfill the requirment that i have asked in question or explain what you have in this loop. Many Thanks, adnna
Many Thanks, Adnan Rafiq muhammadadnanrafiq@gmail.com