Check if DataRow exists by column name in c#?

Posted by waqasahmed on Stack Overflow See other posts from Stack Overflow or by waqasahmed
Published on 2010-04-01T20:39:54Z Indexed on 2010/04/01 20:43 UTC
Read the original article Hit count: 279

Filed under:
|
|

I want to do something like this:

   private User PopulateUsersList(DataRow row)
        {
            Users user = new Users();
            user.Id = int.Parse(row["US_ID"].ToString());
            if (row["US_OTHERFRIEND"] != null)
            {
                user.OtherFriend = row["US_OTHERFRIEND"].ToString();
            }
            return user;
        }

However, I get an error saying US_OTHERFRIEND does not belong to the table. I want to simply check if it is not null, then set the value.

Isn't there a way to do this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about datarow