您的位置:首页 > 数据库

命令行状态下读取数据库连接文件的方法

2008-06-15 13:25 183 查看
在.NET 2.0中对配置文件app.config文件的读写变得相当简单了,在创建一个新的项目后VS2005会自动生成配置文件(Settings.settings)及app.config,如没有请:右键项目--属性--设置里添加一条配置信息,VS2005将自动生成这些文件:

Settings.Designer.cs

namespace WindowsApplication1.Properties

{

internal sealed partial class Settings :

global::System.Configuration.ApplicationSettingsBase

{

private static Settings defaultInstance = ((Settings)

(global::System.Configuration.ApplicationSettingsBase.Synchronized(

new Settings())));

public static Settings Default

{

get { return defaultInstance; }

}

[global::System.Configuration.UserScopedSettingAttribute()]

[global::System.Configuration.DefaultSettingValueAttribute("Form1")]

public string testSetting

{

get { return ((string)(this["testSetting"]));    }

set { this["testSetting"] = value;               }

}

}

}

VS2005基本都完成了,现在我们读写时就只需要写几行代码就行了:

Properties.Settings config = Properties.Settings.Default;

//读取

string str = config.testSetting;

//写入

config.testSetting = "test value";

config.Save();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: