2
Reply

How to check if a session has a record in a named table

Emeka Okoye

Emeka Okoye

Jun 18 2016 9:05 AM
304

 

Hello friends,

I am new to this and I need help.

 

I am working on a application, but is having little problem.

 

The application will work like this:

When a user login to his member area, he will click a button that will take him to another page I called “UserGamePage”, the click event of the button will check if the user has a record in a data table, if there is no record, it will redirect the user the “CreateGamePage”, but if there is a record, it will redirect to “UserGamePage”

 

Below is a code I put up, I calls for connection from a database class, but when I have a record on the table and the user click on the button, it will still redirect to CreateGamePage”.

 

Please help me and tell me what is wrong with my code.

 

 

 

protected void GoToGamePage_Click(object sender, EventArgs e)

    {

        if (!object.Equals(Session["UserId"], null))

        {

            string creatGamePage = "SELECT Count(1) FROM iGame WHERE (Id = '" + Session["UserId"].ToString() + "')";

            DataTable dt2 = new DataTable();

            dt2 = dbClass.ConnectDataBaseReturnDT(creatGamePage);

            if (dt2.Rows.Count < 0)

            {

                             Response.Redirect("~/CreateGamePage.aspx");

            }

 

            else if(dt2.Rows.Count > 0)

            {

                                    Response.Redirect("~/UserGamePage.aspx");

            }


Answers (2)