Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
How can I access the results from FetchResources as a ResourcesCollection?
posted

The WebScheduleDbProvider class exposes a FetchResources method.  This method returns a collection of resources.

The ResourcesCollection class exposes a GetResourceByName method.  This method allows a client to find a resource without iterating through each resource in the collection.

So, in theory, I should be able to extend any of the WebScheduleDbProvider classes and obtain a specific resource by implementing something like the following code. 

Although the following code compiles, the last line fails at run time when it attempts to cast AllResources (type ICollection) to the ResourcesCollection type.  (see exception message below).

Assuming I need to obtain a list of resources by name and I don't want to iterate through each resource returned by FetchResources, what's a good way to do this?

Thanks in advance!  :)

using System;

using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Web.UI;
using Infragistics.WebUI.Data;
using Infragistics.WebUI.WebSchedule;

 

public class My_WebScheduleDbProvider : 

WebScheduleSqlClientProviderIDataFetchIDataUpdate

{

  protected override void OnLoad(EventArgs e)
  {
    ICollection AllResources = this.FetchResources();
    String ResourceName = "My Resource Name";
    Resource resource = 
      ((ResourcesCollection)AllResources)
.GetResourceFromName(ResourceName);

  }

}

Message : Unable to cast object of type 'System.Collections.ArrayList' to type 'Infragistics.WebUI.WebSchedule.ResourcesCollection'.

Parents
  • 37874
    posted

    Hi Jason,

    It has been some time since your post but in case that you still need assistance I will be happy to help.

    I made some research and it seems that casting ICollection to ResourcesCollection is not possible. I would suggest that you try getting a specific resource by name through iteration. The code should look similar to the following:

            ICollection AllResources = WebScheduleOleDbProvider1.FetchResources();

            Resource resource = new Resource();

            foreach (Resource  res in AllResources)

            {

                if (res.Name == "Some Name")

                {

                    resource = res;

                }

            }

    Please let me know if you have any other questions.

Reply Children
No Data