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.
sabrina_spillaneAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
cmi = (MemberInfo)((ArrayList)cmc.GetByCommittee(cmteId))[0];"

Bob
0
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
 
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
 
sabrina_spillaneAuthor Commented:
Thanks Bob very much it work great.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.