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\VSW ebCache\de v-myaans\D esktopModu les\CmteCo rner\EvtRe qInfo.ascx .cs(162): Cannot implicitly convert type 'System.Collections.ArrayL ist' 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.
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\VSW
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.txtName.Text = mi.ContactName.ToString();
Has anyone got any ideas, thanks in advance for all the help.
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
Eg.
mi = mc.GetByCommittee(cmteId);
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
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().Ge tByCommitt ee(cmteId) ; //this is the name of the Stored procedure that I want to access
infoList = DotNetNuke.CBO.FillCollect ion(idr, typeof(MemberInfo));
}
finally
{
if (idr!=null)
{
idr.Close();
idr.Dispose();
idr = null;
}
}
return infoList;
}
}
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().Ge
infoList = DotNetNuke.CBO.FillCollect
}
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
1) .NET 2005?
2) ASP.NET 2.0?
3) DotNetNuke 4.0?
Bob
ASKER
DotNetNuke version 2 and .Net 2003 thanks again by the way.
ASKER
I tried casting it like what was suggested above however I get the following errors?
"Cannot convert type 'aacc.CmteCorner.MemberInf o' to 'System.Collections.ArrayL ist'"
for - "ArrayList cmiArrayList = (ArrayList) cmi;"
and
"Cannot implicitly convert type 'System.Collections.ArrayL ist' to 'aans.CmteCorner.MemberInf o'"
for - "cmi = cmc.GetByCommittee(cmteId) ;"
"Cannot convert type 'aacc.CmteCorner.MemberInf
for - "ArrayList cmiArrayList = (ArrayList) cmi;"
and
"Cannot implicitly convert type 'System.Collections.ArrayL
for - "cmi = cmc.GetByCommittee(cmteId)
ASKER
Any ideas anyone?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Bob very much it work great.
Bob