There is a simple way to assign a value to a DataRow with the conditional operator, otherwise what would be the best way to achieve something similar.
int lastParent = 0;
foreach (DataRow dataRow in parentTable.Rows)
{
//Si la columna "IdParent" existe que asigne el valor.
lastParent = (dataRow?["IdParent"]) ? (int)dataRow["IdParent"] : (int)dataRow["IdUser"];
}
Hope someone can help me. Thanks in advance.
If what you are trying to do is see if the named column exists , the
IdParent
code would be something like this:But if what you are trying to do is check that the row in which you find the column
IdParent
(which you know exists) has a value, it would look something like this:I hope it helps you.
Please reply if it works for you.