zoukankan      html  css  js  c++  java
  • C#2005用XML来保存连接数据库的字符串(这样改变了服务器连接配制只需改一下这个文件就成了),琢磨了几天终于有解了,和大家分享一下,希望高手指点!

    在BIN目录下建一个名为app.config的XML文件,内容如下:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
        </configSections>
        <connectionStrings>Data Source=NIU;Initial Catalog=glass_test;Persist Security Info=True;User ID=sa;Password=2008</connectionStrings>
    </configuration>



    //////////////////////////////////////////下面是程序中获取连接字串到变量ConStr的方法///////////////////////////
    //读取app.config里的连接数据库的字串
    //加引用空间
    using System.Xml;
    //主要代码 
        string ConStr=null;    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load("app.config");
                    XmlNodeList elemlist = doc.GetElementsByTagName("connectionStrings");
                    ConStr = elemlist[0].InnerXml;
                }
                catch { MessageBox.Show("读取XML文件出错,请重试!"); }
  • 相关阅读:
    C++ 构造函数初始化列表
    虚函数
    thread 学习
    vim学习笔记
    Python重载比较运算符
    python使用插入法实现链表反转
    【好文转】Python中yield的理解与使用
    【转】Python中自定义可迭代对象
    linux安装python3.6.6和新建虚拟环境
    【转】Python 并行分布式框架 Celery
  • 原文地址:https://www.cnblogs.com/hrx521/p/1055245.html
Copyright © 2011-2022 走看看