-1

Can someone show me how to loop through a datatable for a value of 'true' and if that value is true set it to a string? I am not sure how to write it and I started to write a foreach. Can someome show me how to finsh it with their own values?

foreach (DataRowView drv in dttestGroups.DefaultView)
{
    foreach (DataRow rowSec in ud.m_UsertestGroupsTable.Rows)
    {
        {

        }
    }
}
qJake
  • 16,821
  • 17
  • 83
  • 135
user2292217
  • 213
  • 2
  • 4
  • 11

1 Answers1

3
foreach (DataRowView drv in dttestGroups.DefaultView)
{
    foreach (DataRow rowSec in ud.m_UsertestGroupsTable.Rows)
    {
        {
             if( (bool)rowSec["ColumnName"] == true)
             // or if((bool)rowSec[columnIndex] == true)
             {
                 //do something. 
             }
        }
    }
}

Notes:

  1. You have to know the the column is of type bool. otherwise it will throw an exception.
  2. You can't set the same column's value to a string.
Mahmood Dehghan
  • 7,761
  • 5
  • 54
  • 71