Click here to Skip to main content
15,867,765 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I want to find relationship between two members,First time I am finding the Bottom Members
of Source_member,Then I am Taking each member and pushing every one on the stack(List<>) and try to find its
bottom members.If Destination_Member Doesn't found I want to remove this Member From List<>,How to remove this Members from List<>

C#
//sSQL = sql query to find out AF_MemberID

                DS = new DataSet();
                da = new OdbcDataAdapter(sSQL, conn);
                da.Fill(DS);

                if(DS.Tables.Count > 0)
                {
                    if (DS.Tables["table"].Rows.Count > 0)
                    {
                        for(int i = 0; i < DS.Tables["table"].Rows.Count; i++)
                        {
                            //Take this Member And Find Out Its related Families Excluding entire Source Member's family
			   alRelationPath.Add(DS.Tables["table"].Rows[i]["AF_MemberID"].ToString());

                           lsFamilyMemberID.Add(DS.Tables["table"].Rows[i]["AF_MemberID"].ToString());

                           AllFamilyID(lsFamilyMemberID, 0);

                           lsFamilyMemberID.RemoveAt(lsFamilyMemberID.Count-1);
                        }
                    }
                }



C#
protected List<String> AllFamilyID(List<String> Member, int depth)
         {
         List<String> lsAllFamilyID = new List<String>();
         if (++depth < 5)
         {
            String strMember = String.Join(",", Member.ToArray());
            
	    //sSQL=Query to Find out AF_FamilyID

            DS1 = new DataSet();
            da1 = new OdbcDataAdapter(sSQL, conn);
            da1.Fill(DS1);

            if (DS1.Tables.Count > 0)
            {
                if (DS1.Tables["table"].Rows.Count > 0)
                {
                    for (int j = 0; j < DS1.Tables["table"].Rows.Count; j++)
                    {
                        bool WhetherContains = lsAllFamilyID.Contains(DS1.Tables["table"].Rows[j]["AF_FamilyID"].ToString());
                        {
                            if (!WhetherContains)
                            {
                                lsAllFamilyID.Add(DS1.Tables["table"].Rows[j]["AF_FamilyID"].ToString());
                            }
                        }
                        AllMemberID(lsAllFamilyID, depth);
                    }
                }
            }
            DS1.Dispose();
            da1.Dispose();
         }
         return lsAllFamilyID;
      }



C#
List<String> lsAllMemberID = new List<String>();
    protected List<String> AllMemberID(List<String> Family, int depth)
    {
        if (++depth < 5)
        {
            String strFamily = String.Join(",", Family.ToArray());

            sSQL = "SELECT AF_MemberID FROM AllFamily_Master";
            sSQL = sSQL + " WHERE AF_FamilyID IN (" + strFamily + ")";
            sSQL = sSQL + " AND AF_MemberType IN ('S','D')";

            DS2 = new DataSet();
            da2 = new OdbcDataAdapter(sSQL, conn);
            da2.Fill(DS2);

            if (DS2.Tables.Count > 0)
            {
                if (DS2.Tables["table"].Rows.Count > 0)
                {
                    for (int k = 0; k < DS2.Tables["table"].Rows.Count; k++)
                    {
                        bool WhetherContains = lsAllMemberID.Contains(DS2.Tables["table"].Rows[k]["AF_MemberID"].ToString());
                        {
                            if (!WhetherContains)
                            {
                                lsAllMemberID.Add(DS2.Tables["table"].Rows[k]["AF_MemberID"].ToString());
                            }
                        }
                        alRelationPath.Add(DS2.Tables["table"].Rows[k]["AF_MemberID"].ToString());
                        if (CheckMember(lsAllMemberID, lblUserToMemberID.Text))
                        {
                            return lsAllMemberID;
                        }
                        else
                        {
                            //alRelationPath.RemoveAt(alRelationPath.Count-1);
                            AllFamilyID(lsAllMemberID, depth);

                        }
                    }
                }
            }
            DS2.Dispose();
            da2.Dispose();
        }
        return lsAllMemberID;
    } 
Posted
Comments
CHill60 8-Mar-14 7:55am    
You already have a call to RemoveAt (not the most efficient way but it would do). What is the actual problem here?
SVT02 8-Mar-14 7:58am    
but its going to remove an only one elements from stack,but i want to remove those elements which are added during the for loop
gggustafson 15-Mar-14 14:11pm    
Why can't you maintain a Stack containing each item added? Then, remove each item popped from the stack.
gggustafson 15-Mar-14 14:19pm    
Why can't you maintain a Stack of the items added and then remove the items on the Stack?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900