Click here to Skip to main content
15,113,225 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In My DataTable1 records are like this

Pk col1 col2
100 1 1
101 1 2
102 1 3
103 2 4
104 2 5
105 2 6

now , by using this DataTable1 i'm filter the Records by using col1 (1 ,2 )
and store the Records in to my new DataTable2 .My new DataTable is like this

Pk col1 col2
100 1 1
101 1 2
102 1 3

This is my new DataTable2 , in my new DataTable2 i do some sorting Process,After Sorting My new DataTable2 is like this

Pk Col1 Col2
100 1 3
101 1 1
102 1 2

This is my new DataTable2,
now what i want is to Replace DataTable2 to DataTable1 data by using PK Column.

After Replacing My DataTable1 is like this ,

PK Col1 Col2
100 1 3
101 1 1
102 1 2
103 2 4
104 2 5
105 2 6

Plz Help me to do this...
Posted

Click on following link and see sorting example in datatable

http://www.dotnetfunda.com/articles/article131.aspx[^]
   
When you are replacing the DataTable1 with DataTable2, it will replace the value from the top index(means 0).So you have to take the count(XX) of replacing table(DataTable2) and after replaced get the count of DataTable1 and delete the index's above the count(XX).

Ex:
C#
dTable.Rows[XX].Delete();
   
Comments
naveensanagasetti 3-Aug-12 7:38am
   
Could u explain with example
   
for(int i=DataTable2.Rows.Count();i<=DataTable1.Rows.Count();i++)
{
DataTable1.Rows[i].Delete();
}


if you find this as useful rate this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900