Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
string TEMPID = "";
            string Pid = "";
            
            //bool MYFLAG = false;
            SqlConnection con3 = new SqlConnection(ConfigurationManager.ConnectionStrings["amms"].ConnectionString);
            con3.Open();
           i = 1;
            while ( i <= 10)
            {
                SqlDataReader RDR;
               
                SqlCommand CMD2 = new SqlCommand("SELECT ParentId FROM Members WHERE MemId='" + lblMemId.Text + "'", con3);
                RDR = CMD2.ExecuteReader();
                while (RDR.Read())
                {
                   // Response.Write("<script> alert('" + RDR[0].ToString() + "'); </script>");
                    ListBox1.Items.Add(RDR[0].ToString());
                    TEMPID = RDR[0].ToString();
                    if (RDR[0].ToString() != "421")
 
                        TEMPID = lblMemId.Text;
                        lblMemId.Text = Pid;
                        Pid = TEMPID;
                      //  MYFLAG = true;
                    
                }
                RDR.Close();
                i++;
 
and my database table is:
 

MemId	ParentId   ThroughOverId     Leg	lleg	rleg
452	253	        253	     Right	172	586
172	452	        452	     Left	948	651
586	452	        452	     Right	172	973
948	172	        172	     Left	773	885
773	948	        948	     Left	333	430
333	773	        773	     Left	715	757
715	333	        333	     Left	637	759
973	586	        586	     Right	379	
757	333	        333	     Right		
885	948	        948	     Right		
379	973	        973	     Left		
430	773	        773	     Right		
172	586	        586	     Left		651
651	172	        172	     Right		
637	715	        715	     Left		
759	715	        715	     Right		
 
HOW TO FIND THE ALL PARENT OF 757 i.e, 333,773,948,172,452(just example) upto 11 level.
 
[edit]Code block added - OriginalGriff[/edit]
Posted 13-Oct-12 5:58am
Edited 13-Oct-12 6:00am
v2
Comments
Wes Aday at 13-Oct-12 12:06pm
   
Wow... 4 reposts... almost SPAM
Kenneth Haugland at 13-Oct-12 12:38pm
   
New record? Is he close?
Wes Aday at 13-Oct-12 18:16pm
   
I have personally seen 6 reposts.
Sergey Alexandrovich Kryukov at 14-Oct-12 2:18am
   
I removes one or more, after I answered one of the questions, so it could be even more. I call it spam.
OP is advised to use only one page for one question: comment on existing posts, use "Improve question".
 
Persistent re-posts can cause abuse reports which eventually cause revocation of CodeProject membership!
 
--SA
Sergey Alexandrovich Kryukov at 14-Oct-12 2:19am
   
It means trying to avoid solving the problem independently. Answering is pretty much useless in such cases.
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

DECLARE @FindParentsForMember INT;
SET  @FindParentsForMember = 757;
WITH Hierarchy(MemId,ParentId) 
AS(
     SELECT DISTINCT parent.MemId,parent.ParentId
     FROM Members parent
     WHERE parent.MemId = @FindParentsForMember
 
     UNION ALL
 
     SELECT child.MemId,child.ParentId
     FROM Members child
     INNER JOIN Hierarchy parent ON parent.ParentId = child.MemId
)
SELECT DISTINCT ParentId
FROM Hierarchy
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100