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"
var gCmd = new SqlCommand(@"SELECT User_id FROM Table_xyz", nCon); SqlDataAdapter Sda = new SqlDataAdapter(gCmd); DataTable Dt = new DataTable(); Sda.Fill(Dt); for (int i = 0; i < Dt.Rows.Count; i++) { string referenceid = Dt.Rows[i]["User_id"].ToString(); var gCmd1 = new SqlCommand(@"SELECT User_id FROM Table_xyz WHERE Reference_id = '" + referenceid + "'", nCon); SqlDataAdapter Sda1 = new SqlDataAdapter(gCmd1); DataTable Dt1 = new DataTable(); Sda1.Fill(Dt1); Response.Write(referenceid); }
var gCmd = new SqlCommand(@"SELECT User_id FROM Table_xyz", nCon);
SqlDataAdapter Sda = new SqlDataAdapter(gCmd);
DataTable Dt = new DataTable(); Sda.Fill(Dt);
for (int i = 0; i < Dt.Rows.Count; i++)
{
string referenceid = Dt.Rows[i]["User_id"].ToString();
var gCmd1 = new SqlCommand(@"SELECT User_id FROM Table_xyz WHERE
Reference_id = '" + referenceid + "'", nCon);
SqlDataAdapter Sda1 = new SqlDataAdapter(gCmd1);
DataTable Dt1 = new DataTable();
Sda1.Fill(Dt1);
Response.Write(referenceid);
}