Link to home
Start Free TrialLog in
Avatar of sabrina_spillane
sabrina_spillane

asked on

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.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I don't understand what you want to do with this ArrayList.  Do you want to create multiple values, or single values?

Bob
Avatar of patspam
patspam

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
Avatar of sabrina_spillane

ASKER

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;            
}
}
I need to clear up some assumptions:

1) .NET 2005?

2) ASP.NET 2.0?

3) DotNetNuke 4.0?

Bob
DotNetNuke version 2 and .Net 2003 thanks again by the way.
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);"


Any ideas anyone?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Bob very much it work great.