Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have to pass a count value to another namespace here. I have 2 classes Select.cs and Value.cs. Select.cs has the following code:
C#
public bool Login(string UserName, string Password)
    {
        string strinvselect = string.Format("select * from newlog where
                              pass='{0}'", Password);

        DataTable dtlog = ExecuteStatement(strinvselect);

        if (dtlog.Rows.Count == 1)
        {
            string strvalue = string.Format("Select * FROM login WHERE uid= 
                                           '{0}'", UserName);

            DataTable newlogin = ExecuteStatement(strvalue);

            try
            {
                if (newlogin.Rows.Count == 1)
                {
                    loginStatus = true;
                }
            }
            catch (Exception ex)
            {
                loginStatus = false;
            }

            return loginStatus;
        }
    }


I have to create a count value if(newlogin.Rows.Count == 1), count=1 and this value should be available in Value.cs to check a functionality. In Value.cs a function getdetails() is called. Here I need to check

C#
if (count == 1)
        {
            getdetails();
        }
        else
        {
            // call another function
        }
Posted

Namespaces are not really relevant here, the issue is that you need to access the variable from a different class. The way you have "global" variables that are specific to the user is the Session, so store the value in a Session variable and have your other class access the Session variable.

Your login function
C#
Session["myData"] = someIntValue;


Your Value function

C#
int x;

if (Session["myData"] == null)
{
   // handle the data not being set
}
else
{
   x = (int)Session["myData"];
}
 
Share this answer
 
Comments
RENJITH VS 9-Mar-15 6:32am    
Thanks F-ES Sitecore :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900