문제

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)
    {
        {

        }
    }
}
도움이 되었습니까?

해결책

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.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top