forum

Home / DeveloperSection / Forums / Using if statement to check individual value returned from a query

Using if statement to check individual value returned from a query

Anonymous User 1894 25-Mar-2015

I have a seleect query which the return query is used in an if statement. 

The query is correct, but the problem is becuase the query returns value from multiple rows it doesnt work. 

I want to use the if statement to check individual values retrived by the query. 

string security = "SELECT ProjectId FROM Project_List WHERE (ProfileId = (SELECT ProfileId FROM User_Profile WHERE (UserId = @UserId)))";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
    myConnection.Open();
    SqlCommand myCommand = new SqlCommand(security, myConnection);
    myCommand.Parameters.AddWithValue("@UserId", currentUserId); 
    if (Request.QueryString["ProjectId"] == myCommand.ExecuteReader().ToString())
    {
 
    }
    else
    {
         Response.Redirect("projectlist.aspx");
    }
}

Updated on 25-Mar-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By