日期:2014-05-20  浏览次数:20755 次

app.config读取问题
winform程序,.net2.0新建后都会有app.config文件,编译后生成xxx.exe.config文件,我知道在程序中可以通过configuration.AppSettings[ "DataBase "]来读取appsetting字节里面的内容,但如何读取 <connectionStrings> 段的内容?还有如何将textbox字段写入?

附一个简单app.config
<?xml   version= "1.0 "   encoding= "utf-8 "   ?>
<configuration>
        <configSections>
        </configSections>
        <connectionStrings>
                <add   name= "abc.Properties.Settings.abcConnectionString "
                        connectionString= "Data   Source=local;Initial   Catalog=database;Persist   Security   Info=True;User   ID=sa;Password= "
                        providerName= "System.Data.SqlClient "   />
        </connectionStrings>
    <appSettings>
        <add       key= "DataBase "       value= "Access "/>
    </appSettings>
</configuration>

------解决方案--------------------
学习!
------解决方案--------------------
接分~
------解决方案--------------------
我也跟着学
------解决方案--------------------
for example:

App.config

<?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<connectionStrings >
<add name = "ConStr " connectionString = "server=.;database=student;uid=sa;pwd=0421 " providerName = "System.Data.SqlClient "/>
</connectionStrings>
</configuration>

取得连接字符串:
Console.WriteLine(ConfigurationManager.ConnectionStrings[ "ConStr "].ConnectionString);

输出:
server=.;database=student;uid=sa;pwd=0421


------解决方案--------------------
jf
------解决方案--------------------
jf
------解决方案--------------------
string a=System.Configuration.ConfigurationSettings.AppSettings[index]
------解决方案--------------------
jf