Programing QA

Programing/Developing Questions & Answers. Focus on business application material

Convert WorkItemCollection to ADO.NET DataTable – Turn TFS query result to ADO.NET DataTable.

Very simple to so:


Code Snippet
  1. // connect to TFS
  2. System.Net.NetworkCredential cre = new System.Net.NetworkCredential("username", "password", "domain");
  3. TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName("http://myserver:8080/MyCollection"), cre);
  5. // get the workitem store for selected collection
  6. WorkItemStore store = tfs.GetService<WorkItemStore>();
  8. // Query for the work items we want
  9. string wiqlQuery = "Select ID, Title from Issue where (State = 'Active') order by Title";
  10. WorkItemCollection l = store.Query(wiqlQuery);
  12. DataTable dt = new DataTable();
  14. foreach (WorkItem wi in l) // loop thru all work items in result
  15. {
  16.     DataRow dr = dt.NewRow(); // add new row in datatable foreach work item in result
  18.     foreach (Field field in wi.Fields) // loop thru all fields in work item
  19.     {
  20.         // Make sure data table contains the right column and add it if not.
  21.         if (!dt.Columns.Contains(field.Name))
  22.             dt.Columns.Add(field.Name);
  24.         string value = string.Empty;
  25.         // make sure value is not null and add it to right data column of the data table.
  26.         if (field.OriginalValue != null)
  27.             value = field.OriginalValue.ToString();
  28.         dr[field.Name] = value;
  29.     }
  30. }
  • My Website

    3/15/2015 6:08:18 AM |

    wow, awesome blog post.

  • rental mobil di surabaya

    3/17/2015 12:51:26 PM |

    Really appreciate you sharing this blog article.Much thanks again. Really Great.

  • here are the findings

    3/18/2015 8:32:55 AM |

    I simply want to say I'm new to weblog and definitely liked you're page. Likely I’m want to bookmark your blog . You surely have exceptional articles. Kudos for sharing with us your web site.

  • Shelba Sheakley

    3/27/2015 11:16:00 PM |

    Hello There. I found your weblog using msn. That is a very well written article. I will be sure to bookmark it and come back to learn more of your useful information. Thanks for the post. I will certainly return.

  • web index

    4/4/2015 7:41:13 PM |

    Aw, this was a really nice post. In idea I would like to put in writing like this additionally – taking time and actual effort to make a very good article… but what can I say… I procrastinate alot and by no means seem to get something done.

Comments are closed