|
-
Nov 24th, 2006, 10:19 PM
#1
Thread Starter
Hyperactive Member
[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.
-
Nov 24th, 2006, 10:46 PM
#2
Re: Global variable problem.
Code:
SqlConnection sqlCon = new SqlConnection(CGlobal.g_szConnString);
-
Nov 24th, 2006, 11:45 PM
#3
Thread Starter
Hyperactive Member
Re: Global variable problem.
Ah! Thank you very much jmcilhinney, I didn't know you had to type classname. before the variable to be used. I miss #include or modules in vb. I appreciate the fast response, that will save me a lot of time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|