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);




Reply With Quote