Home > Archive > C# > January 2006 > Datacolumn Value changing method
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Datacolumn Value changing method
|
|
| plmanikandan@gmail.com 2006-01-18, 3:58 am |
| Hi,
I have a datatable with two datacolumns as below
Name(text) status(int)
wws 0
ddd 1
ggg 0
hhh 0
cfff 1
Status datacolumn will have values either 0 or 1 only.
I need to change the value 0 as "Pass" and 1 as "Fail".
for changing the values i loop through each row and replace 0 as
"Pass" and 1 as "Fail".
for(int i=0;i<dataTable.rows.count;i++)
{
if(dataTable.Rows[i][1].ToString()==int.Parse("0"))
{
dataTable.Rows[i][1]="Pass";
}
if(dataTable.Rows[i][1].ToString()==int.Parse("1"))
{
dataTable.Rows[i][1]="Fail";
}
}
I think above method takes more time,because it loops through each row
and replace the value.
Is there any way to replace all the values in the datacolumn
simultaneously with out looping
Regards,
Mani
| |
| Bruce Wood 2006-01-18, 7:02 pm |
| You could add a third, calculated column that derives its value from
your status column.
Take a look at DataColumn.Expression. Down near the bottom of the
documentation page, it describes an IIF function, that you might be
able to use like this:
IIF(status=1,'Pass','Fail')
Another way to do this, rather than creating a third, calculated
column, is to use a DataView with two columns: the first one the Name
(same as the column in the backing DataTable), the second one
calculated using the expression formula above.
| |
| plmanikandan@gmail.com 2006-01-20, 3:58 am |
| hi,
Thanks for your reply.i also created third column using experssion and
display the column
Regards,
Mani
|
|
|
|
|