[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1114
  • Last Modified:

How do I parse an ArrayList?

I have a controller in my controller class called MemberController which calls a Stored Procedure in my SqlDataProvider class. This Stored procedure returns an arraylist of values. The controller contains the ArrayList GetCmteMember that refers to what the Stored Procedure returns.
I then want to call this controller in my Member class and get an item out of the array. I don't want all of the information in the array just the name. Does anyone know the syntax for this.
Here is some code in how I tried to do it but I get an error saying:
"C:\Documents and Settings\Administrator\VSWebCache\dev-myaans\DesktopModules\CmteCorner\EvtReqInfo.ascx.cs(162): Cannot implicitly convert type 'System.Collections.ArrayList' to 'aans.Member.MemberInfo'"

Code:
//Need to fill the New Request Form with the Users Information (Prefill the form)
//Get the User Contact Name
MemberController cmc = new MemberController();
MemberInfo cmi = new MemberInfo();
mi = mc.GetByCommittee(cmteId); //this method GetByCommittee is an ArrayList
this.txtName.Text = mi.ContactName.ToString();

Has anyone got any ideas, thanks in advance for all the help.
0
sabrina_spillane
Asked:
sabrina_spillane
  • 5
  • 3
1 Solution
 
Bob LearnedCommented:
I don't understand what you want to do with this ArrayList.  Do you want to create multiple values, or single values?

Bob
0
 
patspamCommented:
If mi is an ArrayList, then you should cast it as such. Then you can treat it as an ArrayList.

Eg.

mi = mc.GetByCommittee(cmteId); //this method GetByCommittee is an ArrayList
ArrayList miArrayList = (ArrayList) mi;
// And then whatever you want to do with the arraylist, eg:
foreach (object arrayItem in miArrayList)
{
 /// Do something with arrayItem
}

Or better yet replace "object" with whatever type of objects make up the ArrayList.

Cheers,

Patrick
0
 
sabrina_spillaneAuthor Commented:
This might help.
Below is the controller that references the stored procedure that i want to access to retrieve two fields from the Frist Name and the Last Name and insert it into a txtfield and show it when a user logs onto that page?
The before the controller I have a MemberInfo class which contains the output of the Stored Procedure. I do have a contactName method in here which joins the first name and the last name too.

Does this explain things a bit better? So what I want to do is retrieve two values from the ArrayList. Can anyone help, please. Thanks in advance for all the help.

public class MemberInfo
{
// local property declarations
int _cmteId;
int _personId;
int _userId;
string _firstName;
string _lastName;
int _cmtePositionId;
DateTime _cmteStartDate;
DateTime _cmteEndDate;
string _cmtePositionDesc;
int _cmtePositionRang;

//then the methods.
}

//Here is the source code for the controller from my controller class:

public class MemberController //this is the name of the controller that I am referencing
{
public ArrayList GetByCommittee(int cmteId)
{
ArrayList infoList = null;
IDataReader idr = null;
try
{                        
idr = DataProvider.Instance().GetByCommittee(cmteId); //this is the name of the Stored procedure that I want to access
infoList = DotNetNuke.CBO.FillCollection(idr, typeof(MemberInfo));
}
finally
{
if (idr!=null)
{
idr.Close();
idr.Dispose();
idr = null;
}
}
return infoList;            
}
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Bob LearnedCommented:
I need to clear up some assumptions:

1) .NET 2005?

2) ASP.NET 2.0?

3) DotNetNuke 4.0?

Bob
0
 
sabrina_spillaneAuthor Commented:
DotNetNuke version 2 and .Net 2003 thanks again by the way.
0
 
sabrina_spillaneAuthor Commented:
I tried casting it like what was suggested above however I get the following errors?

"Cannot convert type 'aacc.CmteCorner.MemberInfo' to 'System.Collections.ArrayList'"

for - "ArrayList cmiArrayList = (ArrayList) cmi;"

and

"Cannot implicitly convert type 'System.Collections.ArrayList' to 'aans.CmteCorner.MemberInfo'"

for - "cmi = cmc.GetByCommittee(cmteId);"


0
 
sabrina_spillaneAuthor Commented:
Any ideas anyone?
0
 
Bob LearnedCommented:
cmi = (MemberInfo)((ArrayList)cmc.GetByCommittee(cmteId))[0];"

Bob
0
 
sabrina_spillaneAuthor Commented:
Thanks Bob very much it work great.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now