如何在全局范围内声明变量? [英] How to declare a variable in the global scope?

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

问题描述

你好,


我在ASP.NET / VB页面上工作,我创建了一个变量查询:


Sub Page_Load(sender As Object,e As System.EventArgs)

Dim query as String = String.Empty

...

query = String.Format(" SELECT * FROM dbo.documents WHERE")&查询

结束子


我需要查询全球各地都可以访问。

我该怎么做?


谢谢,

Miguel

解决方案

如果要在所有页面中访问查询变量,则在应用程序范围内声明

变量或将其放入缓存。


-

Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

Miguel Dias Moura < md*REMOVE*moura@*NOSPAM*gmail.com>在消息中写道

新闻:OP ************** @ TK2MSFTNGP09.phx.gbl ...

你好,
我正在开发一个ASP.NET / VB页面,我创建了一个变量查询:

Sub Page_Load(sender As Object,e As System.EventArgs)
Dim query as String = String.Empty
...
query = String.Format(" SELECT * FROM dbo.documents WHERE")&查询
结束子

我需要查询全球各地都可以访问。
我该怎么办?

谢谢,Miguel



使用Web应用程序,通常您的全局变量应存储在

应用程序对象或缓存对象中。通过这种方式,他们很明显地可以使用你的应用程序中的所有代码访问



-

我希望这会有所帮助,

Steve C. Orr,MCSD,MVP
http://史蒂夫.Orr.net

" Miguel Dias Moura" < md*REMOVE*moura@*NOSPAM*gmail.com>在消息中写道

新闻:OP ************** @ TK2MSFTNGP09.phx.gbl ...

你好,
我正在开发一个ASP.NET / VB页面,我创建了一个变量查询:

Sub Page_Load(sender As Object,e As System.EventArgs)
Dim query as String = String.Empty
...
query = String.Format(" SELECT * FROM dbo.documents WHERE")&查询结束


我需要查询全球各地都可以访问。
我该怎么办?

谢谢,Miguel



您好,


您能否告诉我如何在应用程序中存储全局变量

对象?

代码应该是什么我应该放在哪里?


我刚开始使用ASP.NET。


谢谢,

Miguel


" Steve C. Orr [MVP,MCSD]" <圣*** @ Orr.net>写在消息

新闻:St *** @ Orr.net:

使用网络应用程序,通常你的全局变量应存储在
应用程序对象中或缓存对象。通过这种方式,他们可以轻松地访问您应用中的所有代码。

-
我希望这会有所帮助,
Steve C. Orr,MCSD,MVP
http://Steve.Orr.net

Miguel Dias Moura < md*REMOVE*moura@*NOSPAM*gmail.com>在消息中写道

新闻:OP ************** @ TK2MSFTNGP09.phx.gbl ...

你好,
我正在开发一个ASP.NET / VB页面,我创建了一个变量查询:

Sub Page_Load(sender As Object,e As System.EventArgs)
Dim query as String = String.Empty
...
query = String.Format(" SELECT * FROM dbo.documents WHERE")&查询结束



我需要查询全球各地都可以访问。
我该怎么做?
谢谢,
Miguel




Hello,

I am working on an ASP.NET / VB page and I created a variable "query":

Sub Page_Load(sender As Object, e As System.EventArgs)
Dim query as String = String.Empty
...
query = String.Format("SELECT * FROM dbo.documents WHERE ") & query
End Sub

I need "query" to be global and accessible everywhere.
How can I do this?

Thanks,
Miguel

解决方案

If you want query variable to be accessed in all the pages then declare that
variable in application scope or put it in cache.

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl...

Hello,

I am working on an ASP.NET / VB page and I created a variable "query":

Sub Page_Load(sender As Object, e As System.EventArgs)
Dim query as String = String.Empty
...
query = String.Format("SELECT * FROM dbo.documents WHERE ") & query
End Sub

I need "query" to be global and accessible everywhere.
How can I do this?

Thanks,
Miguel



With a web app, generally your global variables should be stored in the
Application Object or Cache object. This way they are explicity made
accessible to all code in your app.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl...

Hello,

I am working on an ASP.NET / VB page and I created a variable "query":

Sub Page_Load(sender As Object, e As System.EventArgs)
Dim query as String = String.Empty
...
query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End
Sub

I need "query" to be global and accessible everywhere.
How can I do this?

Thanks,
Miguel



Hello,

Can you tell me how to store the global variables in the Application
Object?
What should the code be and where should I place it?

I am just starting with ASP.NET.

Thanks,
Miguel

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:St***@Orr.net:

With a web app, generally your global variables should be stored in the
Application Object or Cache object. This way they are explicity made
accessible to all code in your app.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message

news:OP**************@TK2MSFTNGP09.phx.gbl...

Hello,

I am working on an ASP.NET / VB page and I created a variable "query":

Sub Page_Load(sender As Object, e As System.EventArgs)
Dim query as String = String.Empty
...
query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End

Sub

I need "query" to be global and accessible everywhere.
How can I do this?

Thanks,
Miguel




这篇关于如何在全局范围内声明变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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