I need to:

1) Filter Rows by "NodeParent" (which I provide)

2) Sort rows by "Time" and get the most recent entry

Here's what I wrote:

using (SqlConnection con = new SqlConnection(conString))
{
        SqlCommand cmd = new SqlCommand("SELECT TOP 1 NodeID FROM ActivityTable WHERE NodeParent='" + nodeid_previous + "'" + " ORDER BY Time DESC", con);

        con.Open();
        SqlDataReader rdr = cmd.ExecuteReader();
        if (rdr.HasRows)
        {
             while (rdr.Read())
             {
                     nodeid_previous = rdr["NodeID"].ToString();
                     break;
             }
             rdr.Close();
        }
        else
        {
             //so on and so forth..
        }
}

This however doesn't return any results even though I HAVE rows which abide by these conditions. Is the query correct folks? :)

Related posts

Recent Viewed