Andrew
Andrew

Reputation: 7768

How do I check if DataRow contains no nulls

I have a DataRow and I need to make sure that it contains no nulls; Came up with this, but I am not sure how to get the value from the DataColumn

        foreach (DataColumn dc in dr.Table.Columns)
        {
            if (dc == null && !(dc.ColumnName.Equals("id")))
            {
                return false;
            }
        }

Upvotes: 0

Views: 261

Answers (2)

LukeHennerley
LukeHennerley

Reputation: 6434

Table.Columns.Cast<DataColumn>().Where(col => col.ColumnName != "id").Any(col => dr[col] == DBNull.Value);

Upvotes: 3

SLaks
SLaks

Reputation: 887285

if (dc.ColumnName != "id" && dr[dc] == DBNull.Value)

Upvotes: 3

Related Questions