c# - Merge rows in the same DataTable -


i'm trying merge 2 rows 1 row. they're both in same database , table.

example:

        column1    column2    column3    column4    column5    column6 row1    value      value      value      null       null       null row2    null       null       null       value      value      value 

i tried using table.merge(table) didn't seem anything. how can merge these 2 rows it's

        column1    column2    column3    column4    column5    column6 row1    value      value      value      value      value      value 

there no built in function you. such have manually. first determine rows merged, , run on columns merge them.

datarow target = table.rows[0]; datarow source = table.rows[1];  (int = 0; < table.columns.count; i++) {     target[i] = target[i] ?? source[i]; }  table.remove(source); 

the sample above iterates on columns of 2 rows , assigns values source target null. after merge removes source row.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -