Thursday, July 5, 2012

Where & How to create a global variable in for a Connection String in C#

Declare your Global Variable in "Program.cs" file


public static class Globals
{
            public static class db
            {
                public const string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Thisal Lekamge\Desktop\Shohan\new\ChainMan.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
            }
 }


Use it as follows in other .cs files

Trial.Program.Globals.db.connectionString "

Here;



Trial is the name of the Visual Studio Project
Program stands as its a programme.

No comments:

Post a Comment