Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 22nd, 2003, 01:39 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default global variable

hi there:
I need to store my ConnectionString in a variable witch should be accessible from all windows!?! I know there is a way with adding class & some methods & ... but I dont know how to manage it!(its only a idea) please help me to do this!!
Any help appreciated.

Always:),
Hovik Melkomian.
__________________
Always,
Hovik Melkomian.
Reply With Quote
  #2 (permalink)  
Old July 22nd, 2003, 08:50 AM
Authorized User
 
Join Date: Jun 2003
Location: Gainesville, FL, USA.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I usually create a class named Constants in my projects, and stick all the "globals" in there as public static fields.
Thus, for instance

namespace myProject
{
  public class Constants
  {
    public static string CONNSTRING = "myConnection";
  }//Closes Constants class

}//Closes myProject namespace

Then, in another clas sin the myProject namespace, you can get that
string as Constants.CONNSTRING.

Just an idea,
but I bet there are better ways.

HTH,
Olorin
Reply With Quote
  #3 (permalink)  
Old July 23rd, 2003, 12:08 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Put ConnectionString inside the app.config file and load from there.


Reply With Quote
  #4 (permalink)  
Old July 23rd, 2003, 12:52 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

no dear it isnt a good idea since my connection is dynamic & I genarate it?! tnx again for reply.

Always:),
Hovik Melkomian.
Reply With Quote
  #5 (permalink)  
Old July 24th, 2003, 02:12 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

yes! what I need is something like that but it gives me run time error!! how do u see to add a class to project & ...
can u help me?!

Any help appreciate;)

Always:),
Hovik Melkomian.
Reply With Quote
  #6 (permalink)  
Old July 26th, 2003, 01:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Hi Hovik

It could be a class like this one.

    public class Globals
    {
        private string _ConnectionString;
        public Globals()
        {
        }

        public string ConnectionString
        {
            get
            {
                return _ConnectionString;
            }
            set
            {
                _ConnectionString = value;
            }
        }
    }

Make sure that this class resides in the same namespace
where all the other classes that are gonna use this
class are.

You can add the set/get pairs for all the other global variables
that you wanna use in your project.

You can use this class this way.

private Globals globs = null;
.
.
.

    globs = new Globals();
    globs.ConnectionString =
"this is the connection string string set by me.";

.
.
.
MessageBox.Show(globs.ConnectionString);

Write back if there is anything else you wanna ask.

Ankur Verma
.Net and C++ Specialist
Wiley Tech Support
Reply With Quote
  #7 (permalink)  
Old July 26th, 2003, 06:21 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

its ok till now!
But should I new it in every form that I need it?!
my problem is here:)

Always:),
Hovik Melkomian.
Reply With Quote
  #8 (permalink)  
Old July 26th, 2003, 07:13 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

my project name is Dabir so my created class is like this:
using System;

namespace Dabir
{
    /// <summary>
    /// Summary description for Const.
    /// </summary>
    public class Const
    {
        private string ConnDabir;
        public Const()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public string Conn
        {
            set
            {
                ConnDabir = value;
            }
            get
            {
                return ConnDabir;
            }
        }
    }
}

is it still correct,
so now tell me how to use it in other form?! if I new it it'll make all valiables new & null for my Connection string also!
Tell me what to do?!

Always:),
Hovik Melkomian.
Reply With Quote
  #9 (permalink)  
Old March 29th, 2004, 04:33 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Hi again:
I see an sample in net witch ut was using Component to use only one connection in whole App.
now I've created component & insered Connection obj. there, but cant succeed to access its connection & ...
Can any1 help, any help appreciated & tnx in advance.

Always:),
Hovik Melkomian.
Reply With Quote
  #10 (permalink)  
Old March 29th, 2004, 04:45 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Hovik,

Can you define "but cant succeed to access its connection"? What is not working? Do you get an error? If so, what's the error message?
How did you set up your project? Where does the component live and with what kind of application are you trying to access it?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to declare the global variable in global.asax? calyn_gately ASP.NET 3.5 Basics 0 August 6th, 2008 08:06 PM
comapring global variable value to local variable amhicraig XSLT 6 December 5th, 2007 12:16 PM
Global Variable techfreak123 XSLT 0 August 3rd, 2006 07:45 AM
global variable? milk_vanilla Classic ASP Basics 3 January 8th, 2005 06:50 PM
global variable in c# kobystud C# 3 April 22nd, 2004 05:56 AM



All times are GMT -4. The time now is 08:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.