How to use an if loop with a result of system.data.row

1

I have a web service that has a logical data set. When I use LINQ to be able to obtain a parameter that I want, I do it without problems.

Where I find problems is when I call a second web service and I have to make a condition IF to only get certain results based on the status of the project.

How can I integrate the result of the data set with the filter in the IF I have before proceeding with my execution?

This is what I have in the data set web service call:

foreach (WS.ProjectMetaData proj in pr.Distinct(new ProjectEqualityComparer()))
{
   string languages = "";
   string projectId = proj.ProjectID.ToString();
   //calling GetProjectDetails()
   var projectType = client.GetProjectDetails(ref apiKey, ref message, languages);
   var type = projectType.Tables["Table"].Select("ProjectId = '" + projectId    + "'").
              Where(s => s.Field<string>("DefinitionType") != "survey").FirstOrDefault();
}

The part above the code works well for me, because it only gives me the projects that do not have the definition of type "survey"

In the next part of the code I have my condition IF where I also need to filter the projects. So what I'm looking for is that the projects are not expired , Not Published and that do not have as definition survey

Here is how I call the condition:

if (proj.PublishStatus != "expired" && proj.PublishStatus != "Not Published")
    
asked by A arancibia 10.03.2016 в 19:49
source

1 answer

1

You could see to apply the Merge () of the DataTable to accumulate the answers

DataTable.Merge (Method)

DataTable dtMerged = null;

foreach (WS.ProjectMetaData proj in pr.Distinct(new ProjectEqualityComparer()))
{
    string languages = "";
    var projectType = client.GetProjectDetails(ref apiKey, ref message, languages);

    DataTable dt = projectType.Tables["Table"];

    if(dtMerged == null)
    {
        dtMerged = dt.Copy(); //o puedes usar el Clone()
    }

    dtMerged.Merge(dt);

}

at the end of the foreach you will have a single datatable with the data of all the responses that returned GetProjectDetails ()

On this you would apply the linq to filter

    
answered by 10.03.2016 в 22:47