Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam looking into datatable and fetching line by line,

iam having 50 length values. i want to assign 10th length value as "text".

but it is not stored in datarow after assigned

foreach (DataRow row in dtSource.Rows)
                   {


                           if (row.ItemArray[17].ToString().Length > 32)
                           {
                               string ss=   "text";
                               row.ItemArray[17] = ss; // here it is not added in itemarray
                           }


                       }

                   }


What I have tried:

foreach (DataRow row in dtSource.Rows)
                   {


                           if (row.ItemArray[17].ToString().Length > 32)
                           {
                               string ss=   "text";
                               row.ItemArray[17] = ss; // here it is not added in itemarray
                           }


                       }

                   }
Posted
Updated 3-May-18 7:52am
v2

The reference row.ItemArray returns the contents of the row as a new ItemArray. So when you change the value you only change it in the array, not in the row. See DataRow.ItemArray Property (System.Data)[^].
 
Share this answer
 
Comments
Maciej Los 3-May-18 13:47pm    
5ed!
Try this:
C#
foreach (DataRow row in dtSource.Rows)
{
       if (row[17].ToString().Length > 32)
       {
            string ss=   "text";
            row[17] = ss;
       }
}

See: DataRow Class (System.Data)[^]
 
Share this answer
 

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