Results 1 to 3 of 3

Thread: [RESOLVED] Global variable problem.

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    midewest u.s.
    Posts
    275

    Resolved [RESOLVED] Global variable problem.

    Hey everyone,

    Sorry for the dumb question, but I cannot figure this out for the life of me.
    I have searched the forums for an answer to this problem and every thread I have found says I need to create a class and declare the variable as static.

    I created a new class file, and created a class inside of the programs namespace. I declared the variable as a public static string. When I try to use the variable in another file (main form) I get an error stating "The name 'g_szConnString' does not exist in the class or namespace SQLServer.Form1."

    My program name (therefor namespace) is SQLServer, and I am using it in the Form1 class. Is there something I am missing? Do I need to create an instance of the globals class in all of the files that will be using it?

    Thanks in advance.

    Here are a couple code snipptes.

    Code:
    /* Global variable class */
    namespace SQLServer
    {
    	public class CGlobal
    	{
    		public static string g_szConnString = "Data Source=[server];Initial Catalog=[db];User ID=[user];Password=[pass]";
    	}
    }
    Code:
    /* The code that uses the variable */
    SqlConnection   sqlCon = new SqlConnection(g_szConnString);
    Last edited by Tool; Nov 24th, 2006 at 11:46 PM. Reason: Resloved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width