培养良好的习惯,每天一点一滴的进步,终将会有收获。
/// <summary> /// 修改配置文件中的连接字符串 /// </summary> /// <param name="server">服务器名称</param> /// <param name="userid">用户ID</param> /// <param name="password">密码</param> /// <param name="database">数据库名称</param> protected bool ReadXml(string server, string userid, string password, string database) { try { string sqlconstring = "Data Source=" + server + "; User ID=" + userid + "; Password=" + password + "; Initial Catalog=" + database; string path = HttpContext.Current.Server.MapPath("~/web.Config"); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(path); System.Xml.XmlNode node = doc.SelectSingleNode("configuration/connectionStrings/add"); System.Xml.XmlElement eml = (System.Xml.XmlElement)node; eml.SetAttribute("connectionString", sqlconstring); doc.Save(path); return true; } catch(Exception ex) { return false; } }