Sharpeye500
Sharpeye500

Reputation: 9071

XML Doc - null handling

I have

xmlDoc.DataSet.Tables["<tablename>"].Columns

I want to loop through those columns via DataColumn, for say this xmlDoc has 10 entries and 5 are null, then the loop should happen for the non-null entries only.

Any thoughts?

Upvotes: 0

Views: 177

Answers (2)

mledbetter
mledbetter

Reputation: 88

for (int i = 0; i < ds.Tables[0].Columns.Count; i++ )
{
    DataColumn col = ds.Tables[0].Columns[i] != null ? ds.Tables[0].Columns[i] : "<some default value>";
    if (col != "<some default value>")
                    // do something
}

Upvotes: 0

Andrew Hare
Andrew Hare

Reputation: 351688

How about this:

foreach (DataColumn column in xmlDoc.DataSet.Tables[""].Columns)
{
    if (column != null)
    {
        // your code here
    }
}

Upvotes: 2

Related Questions