你如何在全局变量中存储价值 [英] How u store value in global variable

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

问题描述

亲爱的我使用不同部门的登录面板。



主管理员比部门使用。有一个名称部分类似第一级,第二级,第三级。



当我登录时比从数据库存储价值但问题是这个。当新表单打开时,我无法使用数据库中的登录基值。



con.open();

SqlCommand str = new SqlCommand(Select * from Admin where LoginId ='+ LoginId.text .toString +',con);

SqlAdapter adp = new SqlAdapter(str);

DataTable dt = new DataTable(asp);

con.close();



这里我想要stor Levele Id,员工姓名一个Id在新表格的LoginId基础上。

Dear i m using login panel for different department .

Master admin than Department Using . there are one designation Section Like Level one , Level two , level three .

when i login than store value from data base but problem is this . when new form is openning than i m unable to use than login base value from data base.

con.open();
SqlCommand str = new SqlCommand("Select * from Admin where LoginId = '"+LoginId.text.toString +"' ",con);
SqlAdapter adp = new SqlAdapter(str);
DataTable dt = new DataTable(asp);
con.close();

here i want stor Levele Id , Name Of Employee One Id On The base of LoginId in New Form .

推荐答案

在.NET中,没有全局变量。这很好:它们并不是真正需要的并且具有潜在的危险性;使用它们表示不好的风格。在.NET中,一切都有其上下文。



最接近的概念是 Singleton 模式,但即使它很少使用,这真的很有益。你没有解释一个令人信服的理由。请阅读相关内容:

http://en.wikipedia.org/wiki/Singleton_pattern [ ^ ]。



我看到了一些不好的模式实现。可以在这里找到C#中的一个好文章: http://csharpindepth.com/Articles/General/Singleton.aspx [ ^ ]。



-SA
In, .NET, there are no "global variables". And this is good: they are not really needed and are potentially dangerous; using them indicates bad style. In .NET, everything has its context.

The closest concept would be the Singleton pattern, but even it should be used rarely, when it is really beneficial. You did not explain a single convincing reason for that. Please read about it:
http://en.wikipedia.org/wiki/Singleton_pattern[^].

And I saw a number of bad implementations of the pattern. A good one in C# can be found here: http://csharpindepth.com/Articles/General/Singleton.aspx[^].

—SA


这篇关于你如何在全局变量中存储价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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