I want to retrieve all User_id's next after my entered User_id referencing each other from the table by Reference_id, the code below gives the exact result but it retrieves all User_id's from "2001 to 2005".
I want if i enter the "2002" as User_id from a textbox then it must retrieve from "2003 - 2005"
Table_xyz column User_id have value= 2001, 2002, 2003, 2004, 2005
Table_xyz column Reference_id have value= 2000, 2001, 2002, 2003, 2004
C#var gCmd = new SqlCommand(@"SELECT User_id FROM Table_xyz", nCon);C#SqlDataAdapter Sda = new SqlDataAdapter(gCmd);C#DataTable Dt = new DataTable(); Sda.Fill(Dt);C#for (int i = 0; i Dt.Rows.Count; i++)C#{C#string referenceid = Dt.Rows[i]["User_id"].ToString();C#var gCmd1 = new SqlCommand(@"SELECT User_id FROM Table_xyz WHEREC#Reference_id = '" + referenceid + "'", nCon);C#SqlDataAdapter Sda1 = new SqlDataAdapter(gCmd1);C#DataTable Dt1 = new DataTable();C#Sda1.Fill(Dt1);C#Response.Write(referenceid);C#}
I tried adding "SELECT User_id FROM Table_xyz WHERE User_id = '2001'" to the first command but it returns only a single value where User_id matched "2001"

Ruchi SharavatRank #1,713 · 885 reputationPosted Aug 4, 2017, 2:49 AM EDT
Int32 referenceid = textbox1.text; // It will the uersid eg: 2002var gCmd1 = new SqlCommand(@"SELECT User_id FROM Table_xyz WHEREReference_id > " + referenceid + "", nCon);SqlDataAdapter Sda1 = new SqlDataAdapter(gCmd1);DataTable Dt1 = new DataTable();Abdur Razique110 reputationPosted Aug 4, 2017, 3:27 AM EDT
My User_id and Reference_id will have alfa numeric values too (like: ricky_global9, mark09, robin_123)
And your said "Recursive command" will work perfect only if the the datatype is INT or Convert.ToInt.
So the issue still persist for me.
Abdur Razique110 reputationPosted Aug 4, 2017, 3:27 AM EDT
My User_id and Reference_id will have alfa numeric values too (like: ricky_global9, mark09, robin_123)
And your said "Recursive command" will work perfect only if the the datatype is INT or Convert.ToInt.
So the issue still persist for me.
Ruchi SharavatRank #1,713 · 885 reputationPosted Aug 4, 2017, 3:35 AM EDT
Gokhul VarmanRank #1,505 · 1.1K reputationPosted Aug 4, 2017, 4:29 AM EDT