Domanda

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

        }
    }
}
È stato utile?

Soluzione

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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top