1

I reading the all xml data from db I want skip some columns how to skip some columns while reading in for loop Is there any way possible to skip

Reading from row node=1 using XMLElement
foreach (DataColumn col in dt.Columns)
{
   rowelement.Add(get(col.ColumnName,dr[col.ColumnName].ToString())); 
}

2 Answers 2

2

I'm not sure but may be you want something like this

foreach (DataColumn col in dt.Columns)
{
  if(!col.ColumnName.ToLower().Equals("xyz"))
   {
     rowelement.Add(get(col.ColumnName,dr[col.ColumnName].ToString())); 
   }
}

or may be if you have more columns to skip, then you can take them in List.

List<string> columnToSkipped=new List<string>{ "col1", "col2", "col3" };

then use your condition like this

   if(!columnToSkipped.Contains(col.ColumnName.ToLower()))
   {
      rowelement.Add(get(col.ColumnName,dr[col.ColumnName].ToString())); 
   }
2
  • 1
    if (dt.Rows.Count > 0) { dr = dt.Rows[0]; List<string> columnToSkipped = new List<string> { "p", "k"}; foreach (DataColumn col in dtAccounts.Columns) { if (!columnToSkipped.Contains(col.ColumnName.ToLower())) { rowelement.Add(get(col.ColumnName, dr[col.ColumnName].ToString())); //generating Node for each column } } }
    – kvs
    Commented Jun 6, 2013 at 9:08
  • so your "p","k" are the column name? or it's data into column. if these are column name then just check why your if conditional fails
    – Sachin
    Commented Jun 6, 2013 at 9:13
0

In C# we have a nice keyword continue. It does precisely what you need. Usage is very simple.

foreach (DataColumn col in dt.Columns)
{
   if (someCondition) continue; // this skips the current iteration and proceeds with the loop

   rowelement.Add(get(col.ColumnName,dr[col.ColumnName].ToString())); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.