Arraylist to Hashtable

Hello,

I have an arraylist which is built based on a recordset.

                    public ArrayList userRoles=new ArrayList() ;
                    string sqlroles;
                    sqlroles = "Select zrole_id from z360core_user_role where zuser_id="+ UserId ;
                    userRoles = Db.RecordSet(sqlroles);

                    foreach (Hashtable Rl in userRoles)
                    {

                        Response.Write(Rl["zrole_id"]);

                    }
The output is exactly what I wanted. This means that the data is available in the arraylist and hashtable.

I have someother function, I have a value from the db

Convert.ToInt32(Db.ColumnValue("zrole_id"))

I need to check if this value is available in the userRoles arraylist.

If I try to use
if ((userRoles.IndexOf(Convert.ToInt32(Db.ColumnValue("zrole_id")))==-1))
            return false;  
its failing

How should I check if  Convert.ToInt32(Db.ColumnValue("zrole_id")) is there in the userRoles arraylist??

Pls help
sureshrainaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
salan_alaniCommented:
As per your sql select statement, the 'zrole_id' column is in number format (and almost an Int32 format). Therefore your ArrayList will be as the same format for thier objects.
Now I did not understand what is the ColumnValue will retrieve. But anyway, if you want to check if a specified value exist in the userRoles ArrayList, you could use the code below:

int x;
x= 5 // or whatever

if(userRoles.IndexOf(x)==-1)
    return false;


BTW, why you don't move towards the using of ADO.NET rather thatn the traditional ADO if you are using ASP.NET (aspx) application. It is more relaible, no need to add an ActiveX control, and many other features.


Good luck
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.