如何在Windows窗体中存储会话值 [英] how to store value in session in windows form

查看:60
本文介绍了如何在Windows窗体中存储会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 HttpContext.Current.Session [conString] =connectionstring; 

我收到错误:
对象引用未设置为对象的实例。

解决方案

< blockquote>您无法在Windows窗体应用程序中维护会话。您可以在此处使用全局静态变量代替会话。


只需创建一个类



 静态 全球
{
private static string _globalVar = ;

public static string GlobalVar
{
get { return _globalVar; }
set {_globalVar = value ; }
}
}





并将其用作

 GlobalClass.GlobalVar =  任何字符串值 





了解更多 http:// stackoverflow。 com / questions / 1293926 / c-sharp-winforms-global-variables [ ^ ]


Windows窗体中没有会话变量。您可以尝试这个概念

创建一个保存用户名和密码的静态类以及整个应用程序中需要的任何其他变量。



例如:



  public   static   class  LogginInformations 
{
public static string UserID;
}





现在,您可以从代码中的任何位置访问UserID,或者从任何位置设置值。 />
欲了解更多信息,请点击此处。



http://msdn.microsoft.com/en-us/library/79b3xss3(v = vs.80).aspx [ ^ ]


HttpContext.Current.Session["conString"] = "connectionstring";

I am getting error :
Object reference not set to an instance of an object.

解决方案

You can't maintain session in windows form application. Instead of session you can use global static variable here.


Just Create a class

static class Global
{
    private static string _globalVar = "";

    public static string GlobalVar
    {
        get { return _globalVar; }
        set { _globalVar = value; }
    }
}



And use it as

GlobalClass.GlobalVar = "any string value"



Read more http://stackoverflow.com/questions/1293926/c-sharp-winforms-global-variables[^]


There is no Session variables in windows forms.You can try this concept
Create a Static class that holds the User name and password and any other variables need in entire application.

Eg:

public static class LogginInformations
{
    public static string UserID;
}



Now you can access the UserID from anywhere in your code, or set a value from any where.
For more information look on here.

http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx[^]


这篇关于如何在Windows窗体中存储会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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