.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Global variable declaration

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net


I am using the following code:

    var dbSelect = Database.Open("XXXXXX") ;
    var selectQueryString = "SELECT * FROM XXXX ;
    var data = dbSelect.Query(selectQueryString);
Now If I put the above code in try catch block, then "data" variable is not accessible outside try block. How I can declare "data" variable globally and then can collect result in it in try block?

View Complete Post

More Related Resource Links

Function and Variable declaration with out an 'As' clause


I get a message - "Function without an 'As' clause" for HMAC_MD5 and "Variable declaration without an 'As' clause" for Key and Value.  But the code works.  But the messages still exists.  Is there a way to fix this to avoid the messages?

Function HMAC_MD5(ByVal Key, ByVal Value)


Initializing more than one variable at declaration


Guys, i am looking for this using google search but without success yet...

How can I do this:

private string a, b, c, d ,e = "";

I want ALL the variables to start with "" but this is not what i get...  so i am doing this until the answer does not come:

private string a,b,c,d,e;

a = b = c = d = e = "";



Declaration of a Variable in a webform

Hi All, Please review my code, i've removed the most part of the code which is not relevant to this: namespace MyQuiz { public partial class QuizPage : System.Web.UI.Page { protected int[] idquestion = new int[totalQuestions]; public QuizPage() { Page.Init += new System.EventHandler(Page_Init); } private void ReadQuestionsIntoTable() { IEnumerable questions = SelectRows("Select * From Questions WHERE QuizID='48'"); //Ashiq Code int a = 0; foreach (DataRowView question in questions) { a++; } totalQuestions = a; foreach (DataRowView question in questions) { idquestion = new int[totalQuestions]; idquestion[NumberOfQuestions] = Convert.ToInt16(question["QuestionID"].ToString()); } } protected void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { ReadQuestionsIntoTable(); } else { bool AreAllAnswered = CalculateScore(r);

SSRS 2005 SP3 - Instr function with Global Variable fails in Subscriptions

Hi I have a very simple expression in a text box in my report:  INSTR(Globals!ReportServerUrl,"Report").  This expression should return the integer value of where the string "Report" appears in the Global variable for the ReportServerUrl.  Simple enough.  This works fine for generating the report directly through report manager, and in my case returns a value of 20. However when run as a subscription and emailed to myself the value returned is 0. This suggests that the search string does not appear in the Global variable. In the reportserver config file the URLroot tag contains the correct server address - http://myserver/reportserver. Does anyone know why i should be experiencing this issue with my subscriptions?  Your help would be much appreciated! Thanks Guy  Guy

Accessing static variable in global.ashx file


Hi All ,

I want to access the static variable in my global.ashx file  I am using classname.variable name for accessing the variable but the variable name dose not appear.Can someone tell me how to access static varialbe in *.ashx file.

How to get the Package level Variable collections (Global Variable) in Script Task


Hi All,

I have the requirement like read all the Variables in Script Component Task, which includes variables available at package level and their values, global variables declared at package.


Currently are two ways to read the variables but which are not suitable for my requirement


1) Mentioning the variables at Script designer window as ReadOnlyVariables or ReadWriteVariables



Global variable


Hello all!

I need to declare a variable that is global so i can evaluate roles permissions on page load.

How can i do this?

Thanks in advance!

Passing a window.location as a (global?) variable




I have come up with form which pulls membership id, allows checkbox selections and commentry (custom feedback). The final piece that needs to be captured is the iframe's url. Now the content in the iframe is content produced by (madcap) flare.


I need to capture the window.location of the iframe url and pass that onto the asp.net masterpage. The iframe is also located in a content page. The iframes content is controlled by it's own TOC. I have added a script to this output so that each time the content (page) in the iframe changes the script alert's me of the new URL of the page just clicked/opened (this is the information I need passed as a variable).


Here is the code producing the desired alert output (page url).


<script type="text/javascript">
var locationObj = window.location;

The above produces the output I would like to capture (but instead of an alert output, I require this as a string) which will allow the insertion into my form as the final piece of information required.


I am not sure how I can convert or catch the output. Of course I would not want to use the alert function everytime the page changes, but wou

global variable



i am working on a web site. my application is simple dot net application and back hand is sql server. to reduce the hacking of the site can any one suggest me some tips.

i wanna to know that when ever the user login i am creating the session variable is that the safe one Or shall i need to create the application variable for that ?

How do define a global variable in a page



I have to define a global and unchangeable variable in a web page. I used static variable but its content is the same for all users that use the page and it is bad. I dont want use Session variable.

Any idea?

Application variable or static class for global string?


I need to keep a global variable throughout the whole time the user is at my site, but do I use Application or a static class? The string variable should store a region name and my site makes a few changes depending on which region that has been set.

I read that Application was mainly for classic ASP, but I also read that a static class cannot be instantiated at runtime (e.g. when the user has logged in).

So, have I got something wrong here and which solution do I use?



global variable


how to declare out global variable? i tried out but get error..

below is my orginal code

Imports System.Data
Imports System.Data.SqlClient
Partial Public Class Register
    Inherits System.Web.UI.Page

    Public badge As String
    Public fname As String
    Public dpt As String
    Public design As String
    Public shf As String
    Public role As String
    Public site As String
    Public pname As String
    Public preg As String
    Public pgoal As String
    Public pcom As String
    Public poth As String
    Public pdpt As String

    Public Function pronum() As Integer
        Dim mySQL As String
        Dim objCN As New SqlConnection
        Dim objCM As New SqlCommand
        Dim objDR As SqlDataReader
        objCN.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ToString
        objCM.Connection = objCN
        Dim prono As String = ""
        mySQL = "SELECT ProjNo FROM PROJECT"
        objCM.CommandText = mySQL
        objDR = objCM.ExecuteReader()
        While objDR.Read()
            prono = objDR(0)
        End While

        If (prono = "") Then
            Return 1
            Return (Convert.ToInt32(prono) + 1)
        End If
    End Function

 here is what i wish

Sql 2008 Variable declaration


Wondering can we do like below.


SELECT @iSalary = Salary

FROM dbo.udf_Get_Salary(EMP0001)


Instead of doing old conventional way




SELECT @iSalary = Salary

FROM dbo.udf_Get_Salary(EMP0001)


Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

Local variable scoping in C#

In my previous post, Compiler-generated scopes for local variable declarations, I briefly touched on the issue of multiple meanings applied to the same name. In this post, I'll aim to flush out the compiler's rules with regards to binding names in their local scopes.

Compiler-generated scopes for local variable declarations

I was tasked with understanding and fixing a bug on error reporting with foreach iteration variables the other day, and it got me thinking about local variable scoping rules in C# in general. First, the bug.

Retrieving a variable from a previous page



I'm looking to have a search page where a user will select an item from a listview, then then taken to another page that wil display data based on their original selection.

A user will type in a string and be presented with a list of usernames that are like that string, when they select a user name who's profile they would like to view I would like the page that they're taken to, to be that users profile.

How would I transfer the variable from the search page to the profile page, and when I work on the profile page, how can I access that variable?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend