Four Seasons

Hello;

I have question about using globa connection string,

I want to know how can I create global variable, because I want to global connection for all methods

Thank you



Re: Windows Forms Data Controls and Databinding Global connection

Bob zhu - MSFT

Four Seasons

you can store global string by Settings.settings, or store them in xml file as config.






Re: Windows Forms Data Controls and Databinding Global connection

Four Seasons

thank you zbo, but I want to know how can I modify the connection string in app.config by using the global variable

i hope to get the answer as soon as possibleSmile





Re: Windows Forms Data Controls and Databinding Global connection

Bob zhu - MSFT

you can access it like

private void button1_Click(object sender, EventArgs e)

{

string conn=CS2.Properties.Settings.Default.ConnString;

MessageBox.Show(conn);

CS2.Properties.Settings.Default.ConnString = "changed";

conn = CS2.Properties.Settings.Default.ConnString;

MessageBox.Show(conn);

}

CS2 is my project name, my step as follow:
double click settings.settings -> add name ConnString Type as string scope is user value anything you like






Re: Windows Forms Data Controls and Databinding Global connection

Zhi-Xin Ye - MSFT

Four Seasons wrote:

thank you zbo, but I want to know how can I modify the connection string in app.config by using the global variable

i hope to get the answer as soon as possible



See Read/Write App.Config File with .NET 2.0




Re: Windows Forms Data Controls and Databinding Global connection

Four Seasons

hello Zhi-Xin Ye - MSFT

thank you for your useful article,

but the problem is Iam working in visual studio 2005

this code is in 2003

' Get the application configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)

how can I use it in 2005

I need your help





Re: Windows Forms Data Controls and Databinding Global connection

Zhi-Xin Ye - MSFT

The article is alreay for .NET2.0 (VS 2005), but it's written in C#, for VB.NET code, you can try:

Code Snippet

Imports System.Configuration

Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

And remember to add reference to the System.Configuration.Dll