如何将变量传递给另一个命名空间? [英] How to pass a variable to another namespace?

查看:118
本文介绍了如何将变量传递给另一个命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在此处将计数值传递给另一个命名空间。我有2个类Select.cs和Value.cs。 Select.cs具有以下代码:

  public   bool 登录(字符串用户名,字符串密码)
{
< span class =code-keyword> string strinvselect = string .Format( < span class =code-string> select * from newlog where
pass ='{0}',Password);

DataTable dtlog = ExecuteStatement(strinvselect);

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

DataTable newlogin = ExecuteStatement(strvalue);

尝试
{
如果(newlogin。 Rows.Count == 1
{
loginStatus = true ;
}
}
catch (例外情况)
{
loginStatus = ;
}

return loginStatus;
}
}





我必须创建一个计数值if(newlogin.Rows.Count == 1 ),count = 1并且Value.cs中应该可以使用此值来检查功能。在Value.cs中,调用函数getdetails()。在这里我需要检查



  if (count ==  1 
{
getdetails();
}
其他
{
// < span class =code-comment>调用另一个函数
}

解决方案

命名空间并不真正相关在这里,问题是您需要从不同的类访问变量。您拥有特定于用户的全局变量的方式是Session,因此将值存储在Session变量中,让其他类访问Session变量。



您的登录功能

会话[  myData ] = someIntValue; 





您的超值功能



  int  x; 

if (会话[ myData] == null
{
// 处理未设置的数据
}
else
{
x =( int )会话[ myData ];
}


试试以下链接





http://stackoverflow.com/questions/740937/accessing-variables-from-other-namespaces [ ^ ]

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:

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

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

解决方案

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

Session["myData"] = someIntValue;



Your Value function

int x;

if (Session["myData"] == null)
{
   // handle the data not being set
}
else
{
   x = (int)Session["myData"];
}


Try the following link


http://stackoverflow.com/questions/740937/accessing-variables-from-other-namespaces[^]


这篇关于如何将变量传递给另一个命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆